Set filter programatically?

1 Answer 6562 Views
Grid
Bob
Top achievements
Rank 1
Bob asked on 07 Jan 2015, 10:46 PM
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))
    }
}

1 Answer, 1 is accepted

Sort by
0
Bob
Top achievements
Rank 1
answered on 08 Jan 2015, 02:20 PM
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
        });
    }
}





Kiril Nikolov
Telerik team
commented on 09 Jan 2015, 11:57 AM

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.

 
Sam
Top achievements
Rank 1
commented on 21 Jun 2017, 02:16 PM

Thank you for this! 
Tags
Grid
Asked by
Bob
Top achievements
Rank 1
Answers by
Bob
Top achievements
Rank 1
Share this question
or