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

Adding filtering to grid, does not filter table.

1 Answer 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kai
Top achievements
Rank 1
kai asked on 16 Jan 2018, 10:44 AM

The drop down list is populated with values, but when they are selected nothing happens to the table.

I am trying to iterate through the column, get the distinct values and add them to a filter.

It works when i Add a new asp:SqlDataSource with a distinct sql statement, then add datasourceID, datavalue and datatext to the ComboBox, but need to get this working programmatically.

Column:

<telerik:GridBoundColumn DataField="OperationalTypeName" HeaderText="OperationalTypeName" SortExpression="OperationalTypeName">
                    <FilterTemplate>
                        <telerik:RadComboBox ID="operationtypeComboBox" runat="server" RenderMode="Lightweight"
                            SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("OperationalTypeName").CurrentFilterValue %>'
                            OnClientSelectedIndexChanged="OpertationalTypeIndexChanged">
                        </telerik:RadComboBox>

                        <telerik:RadScriptBlock runat="server">
                            <script type="text/javascript">
                                function OpertationalTypeIndexChanged(sender, args) {
                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                    tableView.filter("OperationalTypeName", args.get_item().get_value();, "EqualTo");
                                }
                            </script>
                        </telerik:RadScriptBlock>
                    </FilterTemplate>
               </telerik:GridBoundColumn>

 

ItemDataBound:

    protected void GridView1_ItemDataBound(object sender, GridItemEventArgs e)
    {
         if (e.Item is GridFilteringItem)
        {
            GridFilteringItem item = (GridFilteringItem)e.Item;
            RadComboBox combo = (RadComboBox)item.FindControl("operationtypeComboBox");
            //combo.Items.Add(new RadComboBoxItem("ALL"));
            foreach (var filter in filterOperationalType())

//filterOperatiionType returns the correct list

           {

                combo.Items.Add(new RadComboBoxItem(filter, filter));

// they are added to the ComboBox but do not work, the html generated is exactly the same as the filter options that work through using DataSourceID used on the ComboBox.
            }
        }        
    }

    private List<string> filterOperationalType()
    {

        DataView view = (DataView)this.SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        List<string> list = new List<string>();
        foreach (DataRow item in view.Table.Rows)
        {
            list.Add(item.ItemArray[1].ToString());
        }
        var a = list.Distinct().ToList();
        return a;
    }

 

 

Thank you

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 19 Jan 2018, 08:53 AM
Hi Kai,

Please check out the first attachment (RadGridFilterComboClientAndServerDataBinding.zip) from the following forum post by Eyup:
The sample in that post demonstrates two ways for filtering with a ComboBox as FilterTemplate.

Also note, when binding data programmatically to RadComboBox, it better to do it using its DataBinding event.
<telerik:RadComboBox ... OnDataBinding="RadComboBox_DataBinding">
    ...
</telerik:RadComboBox>

DataBinding event handler C#
protected void RadComboBox_DataBinding(object sender, EventArgs e)
{
    foreach (var filter in filterOperationalType())
    {
        (sender as RadComboBox).Items.Add(new RadComboBoxItem(filter, filter));
    }
}

Please try it out and see if that works for you.

Kind regards,
Attila Antal
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
kai
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or