This is a migrated thread and some comments may be shown as answers.

Grid basic filtering

7 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
berto
Top achievements
Rank 1
berto asked on 05 Aug 2012, 09:34 PM
Can I ask for short quide how to add dropdownlist to filter.

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Aug 2012, 05:23 AM
Hi Berto,

One suggestion is you can add a RadComboBox in the filterTemplate and handle filter in clientside.

ASPX:
<telerik:GridBoundColumn DataField="LastName"  UniqueName="LastName" HeaderText="LastName" >
   <FilterTemplate
       <telerik:RadComboBox ID="ddlFilter" DataSourceID="SqlDataSource1" DataTextField="LastName" DataValueField="LastName"  runat="server" OnClientSelectedIndexChanged="SelectedIndexChanged">
       </telerik:RadComboBox>
   </FilterTemplate>
</telerik:GridBoundColumn>

Javascript:
<script type="text/javascript">
  function SelectedIndexChanged(sender, args)
  {
     var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
     tableView.filter("LastName", args.get_item().get_value(), "EqualTo", true);
  }
</script>

Please take a look into this demo .

Thanks,
Shinu.
0
berto
Top achievements
Rank 1
answered on 08 Aug 2012, 09:06 PM
Thx for tip. I copied above code. I see DDL and I can choose something but filtering does not work.
What can be wrong?

My code:

<telerik:GridBoundColumn DataField="Arzt"
            FilterControlAltText="Filter Arzt column" HeaderText="Arzt"
            SortExpression="Arzt" UniqueName="Arzt">
                <FilterTemplate>
                <telerik:RadComboBox runat="server" ID="ddlArzt" DataSourceID="sqlDDLArzt"
                DataValueField="Arzt" DataTextField="Arzt" AutoPostBack="true"
                AppendDataBoundItems="true"
                SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("Arzt").CurrentFilterValue %>'
                OnClientSelectedIndexChanged="ddlArzt_SelectedIndexChanged">
                <Items>
                <telerik:RadComboBoxItem Text="Alle" />
                </Items>
                </telerik:RadComboBox>
                <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                    <script type="text/javascript">
                        function ddlArzt_SelectedIndexChanged(sender, args) {
                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                        tableView.filter("Arzt", args.get_item().get_value(), "EqualTo");
                        
                    </script>
                </telerik:RadScriptBlock>
                </FilterTemplate>
            <HeaderStyle Width="200px" />
        </telerik:GridBoundColumn>
0
berto
Top achievements
Rank 1
answered on 09 Aug 2012, 04:50 PM
Same issue for 2 way to implement this (http://www.telerik.com/help/aspnet-ajax/grid-filtertemplate.html)

asp:

<telerik:GridBoundColumn DataField="Arzt"
            FilterControlAltText="Filter Arzt column" HeaderText="Arzt"
            SortExpression="Arzt" UniqueName="Arzt">
                <FilterTemplate>
                <telerik:RadComboBox runat="server" ID="ddlArzt" DataSourceID="sqlDDLArzt"
                DataValueField="Arzt" DataTextField="Arzt" AutoPostBack="true"
                AppendDataBoundItems="true" OnSelectedIndexChanged="ddlArzt_SelectedIndexChanged">
                <Items>
                <telerik:RadComboBoxItem Text="Alle" />
                </Items>
                </telerik:RadComboBox>
                </FilterTemplate>
            <HeaderStyle Width="200px" />
        </telerik:GridBoundColumn>

and code file

protected void ddlArzt_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
    string filterExpression;
    filterExpression = "([Arzt] = '" + e.Value + "')";
    rgLLeistungen.MasterTableView.FilterExpression = filterExpression;
    rgLLeistungen.MasterTableView.Rebind();
}

Any idea what can be wrong, I allready lost 4 days for this DDL and still no progress...
0
berto
Top achievements
Rank 1
answered on 09 Aug 2012, 06:50 PM
Just one additional information. I am using stored procedures in SQLDataSource.
0
Shinu
Top achievements
Rank 2
answered on 10 Aug 2012, 04:27 AM
Hi Berto,

The First method works fine at my end.I couldn't replicate any issue on it. The second method also works when the EnableLinqExpression is set to false.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" EnableLinqExpressions="false" AllowFilteringByColumn="true" onneeddatasource="RadGrid1_NeedDataSource1">

Thanks,
Shinu.
0
berto
Top achievements
Rank 1
answered on 10 Aug 2012, 07:38 AM
Thanks for update, unfortuanately it didn't move me closer to solve this issue. Where can be an issue? Must I somehow activate javascript in my project? (So far I did not use it at all). Is it an issue with stored procedures and it should be just select statement. I am out of ideas at that moment. I opened support ticket maybe they can help me...
0
berto
Top achievements
Rank 1
answered on 10 Aug 2012, 09:31 AM
Support solved this issue:

Please note that the tableView.filter command causes the page to perform a postback. Therefore, if the AutoPostBack property of the RadComboBox is enabled, its postback could interfere with the one generated by the filter command. 
Tags
Grid
Asked by
berto
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
berto
Top achievements
Rank 1
Share this question
or