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

Adjust multiple filters from javascript...

3 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 22 Jan 2014, 06:13 PM
I am trying to implement filtering using combo boxes via javascript.  The filtering itself works fine.  The problem arises when the combo box list for column B is dependent on the selection in column A.  To address the dependency, when the user applies a filter to column A, I want it to also clear the filter for column B.  I tried adding a call to clear the filter for column B just prior to setting the filter on column A (see below), but it appears to be producing a double postback which hangs the browser.  Clearing the filter on column B, and applying the filter on column A, each work by themselves (if I comment out the other).  The hang only occurs when I try to do both.

I believe what is happening is that clearing the filter on column B is causing a postback.  Then applying the filter to column A is causing another postback.  The second postback cancels the first...but the browser doesn't realize it and waits for the first postback to time out.

So...the question is...is there a way to modify both filters at the same time so that it only produces a single postback?


<FilterTemplate>
    <telerik:RadComboBox ID="dpdDataCllctnTypFilter" DataSourceID="dsDataCllctnTypFilter" Width="100%"
        DataTextField="Nm" DataValueField="Nm" Height="200px" AppendDataBoundItems="true"
        SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("A").CurrentFilterValue%>'
        runat="server" OnClientSelectedIndexChanged="dpdDataCllctnTypFilterChanged" OnSelectedIndexChanged="cboDcTypFilter_SelectedIndexChanged" >
        <Items>
            <telerik:RadComboBoxItem />
        </Items>
    </telerik:RadComboBox>
    <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
        <script type="text/javascript">
            function dpdDataCllctnTypFilterChanged(sender, args) {
                var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");
                var s = args.get_item().get_value();
 
                tableView.clearFilter("B");     // Added to clear the filter on column B
 
                if (s == '')
                    tableView.clearFilter("A")
                else
                    tableView.filter("A", s, "EqualTo");
            }
        </script>
    </telerik:RadScriptBlock>
</FilterTemplate>


3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 27 Jan 2014, 12:10 PM
Hello Raymond,

You are absolutely correct about the cause of the problem. To resolve the issue, you should leave only one filter operation on the client function and handle the rest of the logic on the server:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        Pair filterDetails = e.CommandArgument as Pair;
        string filterFunction = filterDetails.First.ToString();
        string columnName = filterDetails.Second.ToString();
 
        if (columnName == "ShipCountryA")
        {
            e.Item.OwnerTableView.GetColumn("ShipCountryB").CurrentFilterFunction =
                GridKnownFunction.NoFilter;
        }
    }
}

Hope this helps. Please give it a try and let me know if it works for you.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Raymond
Top achievements
Rank 1
answered on 27 Jan 2014, 04:16 PM
Hi,

Thanks for the response.  I had implemented the filtering in the SelectedIndexChanged event of the combo boxes on the backend.  The back end allows access to all of the filter functionality, so I can do both in one operation.  But I think I like you solution better.
0
Eyup
Telerik team
answered on 30 Jan 2014, 09:41 AM
Hi Raymond,

I'm glad that the suggested approach was helpful.
I hope it will prove helpful to other developers with similar questions as well.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Raymond
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Raymond
Top achievements
Rank 1
Share this question
or