Set filter programatically?

4 posts, 1 answers
  1. Bob
    Bob avatar
    123 posts
    Member since:
    Sep 2012

    Posted 07 Jan 2015 Link to this post

    Hi, I want to set a default filter value for a column on the grid but only if the application is not already persisting state.  My question is how do I set a filter programmatically in this scenario?  There is a Boolean column called "Enabled" that I am trying to default to TRUE when no pervious grid state can be found on client.

    var localStorageKey = "UserAdministrationUserGridOptions";
     
    $(function () {
        // pull client grid state and apply to grid (filters, current page, sorts, etc).
        setGridOptions();
    });
     
    function setGridOptions() {
        var options = localStorage[localStorageKey];
     
        if (options) {
            $("#UserAdministrationUserGrid").data("kendoGrid").setOptions(JSON.parse(options));
        }
        else
        {
        // set initial enabled filter to true
       // HOW DO I DO THIS IN JAVASCRIPT
        // server: .Filter(f => f.Add(m=> m.Enabled).IsEqualTo(true))
        }
    }
  2. Bob
    Bob avatar
    123 posts
    Member since:
    Sep 2012

    Posted 08 Jan 2015 in reply to Bob Link to this post

    If anyone is interested, here's my resolution:

    function setGridOptions()
    {
        var options = localStorage[localStorageKey];
        var grid = $("#UserAdministrationUserGrid").data("kendoGrid");
     
        // if user has saved options, then load them up
        // else, load grid with "enabled only" filter
        if (options) {
            grid.setOptions(JSON.parse(options));
        }
        else
        {
            grid.dataSource.filter({
                field: "Enabled",
                operator: "eq",
                value: true
            });
        }
    }





  3. Answer
    Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2598 posts

    Posted 09 Jan 2015 Link to this post

    Hello Bob,

     

    The dataSource filter method is the recommended way to go.

     

    Thanks for sharing your solution.

     

    Regards,
    Kiril Nikolov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  4. Samuel
    Samuel avatar
    1 posts
    Member since:
    Jun 2013

    Posted 21 Jun in reply to Bob Link to this post

    Thank you for this! 
Back to Top