Complex Filtering With Rad Grid (Client-Side)

2 posts, 0 answers
  1. Mark
    Mark avatar
    7 posts
    Member since:
    Apr 2013

    Posted 13 Mar 2014 Link to this post

    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.
  2. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 18 Mar 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top