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

Javascript filters for radcombobox multiple values

1 Answer 271 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 07 Dec 2011, 11:57 PM

I have a need to filter one column based on what the user selects in a rad combo box. It works fine with one value selected but when two or more values are selectd it will not filter correct. I also need to do this client side so server side is not an option. I think the problem is within the "OR" clause. Anyone have any suggestions?
Thanks for any help,
D

<telerik:GridBoundColumn UniqueName="foundin" DataField="foundin" HeaderText="Fields search term matched"
    HeaderStyle-Width="215px" ItemStyle-Width="215px" FilterControlWidth="215px"
    AllowFiltering="true" ItemStyle-Wrap="True">
    <FilterTemplate>
        <telerik:RadComboBox ID="radcombo_foundin" runat="server" UniqueName="radcombo_foundin"
            Width="200px" OnClientDropDownClosed="filterfoundin" CheckBoxes="true" Filter="Contains" >
        </telerik:RadComboBox>
    </FilterTemplate>
</telerik:GridBoundColumn>


 

function filterfoundin(sender, e) {
    var tableView = $find('<%=rad_SearchResults.ClientID %>').get_masterTableView();
    var filter = "Contains";
    var i = 0;
    var q = "";
    while (i < sender._itemData.length) {
        q += sender._itemData[i].checked ? sender._itemData[i].value : "";
        if (i + 1 < sender._itemData.length) {
            if (sender._itemData[i].checked) {
                q += " OR ";
            }
        }
        i++;
    }
    q = q.substring(q.length - 4) == " OR " ? q.substring(0, q.length - 4) : q;
    var hidden = document.getElementById('<%=hf_foundin.ClientID %>');
    hidden.value = q;
    tableView.filter('foundin', q, filter);
}

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 12 Dec 2011, 11:11 AM
Hi Daniel,

 Indeed the problem is the "OR" clause. The client-side filter function accepts only single value as a filter value parameter so you cannot pass complex filter queries. The only place where you can do this is on the server. You can fire a custom command from the client and intercept it in the ItemCommand server-side event where you can manually construct a filter expression and apply it to the grid.
At the end of the filterfoundin function instead of tableView.filter, you can call tableView.fireCommand("CustomFilterCommand",...some parameters....) as shown in this help topic. An then in the ItemCommand event construct the filter expression as described in this help topic.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName=="CustomFilterCommand")
        {
            RadGrid1.MasterTableView.FilterExpression = "custom filter query";
            RadGrid1.Rebind();
        }
    }

Best wishes,
Marin
the Telerik team
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 RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or