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

Complex Filtering With Rad Grid (Client-Side)

1 Answer 197 Views
ODataDataSource
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 13 Mar 2014, 10:57 PM
I have a RadGrid with client-side binding similar to the "ODataDataSource - Filtering, Sorting and Paging with RadGrid" example.  I have been able to add multiple filter conditions in the past by calling args.set_filterExpressions(filter); multiple times in the "requesting" function (see scripts.js in the example).  However, now I have a specification where I need to search multiple fields for a value (in addition to the other filters on the grid).  So the value might appear in column1,  column2, or column3.  An example of this kind of complex filtering is shown in the list view client-side filtering example

What is the recommended way for a client-side bound RadGrid to have complex filtering expressions?  When calling args.set_filterExpressions(filter), any previous expression uses "AND" logic with the existing expressions.  My resulting filter would be an OData URL as in the list view OData filtering example:
((UnitPrice gt 25 and UnitsInStock lt 40) or (Discontinued ne true and startswith(ProductName,'I') eq true))


Thanks.

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 18 Mar 2014, 12:45 PM
Hi Mark,

To achieve the desired functionality you can try modifying directly the $filter parameter in RadODataDataSource’s Requesting event:
<script type="text/javascript">
    function onRequesting(sender, args) {
        args.get_options().data.$filter = "((UnitPrice gt 25 and UnitsInStock lt 40) or (Discontinued ne true and startswith(ProductName,'I') eq true))";
    }
  
</script>
<telerik:RadODataDataSource runat="server" ID="RadODataDataSource1">
    <ClientEvents Requesting="onRequesting" />
</telerik:RadODataDataSource>
In that way you can build or concatenate complex filter expression and pass it to the $filter parameter. Also you can get formatted grid’s filter expression by using following code snippet:
var filterExpressions =
$find("RadGrid1ClientID").get_masterTableView().get_filterExpressions().toDataService()
 }

I hope this helps.

Regards,
Radoslav
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
ODataDataSource
Asked by
Mark
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or