I am trying to default a Kendo UI grid to be filtered on page load. I have a column with boolean values that I need to only display the ones with "false" on page load but allow the user to see them all if they clear filters.
Example: http://www.telerik.com/forums/adding-filters-to-grid-s-source
function updateSearchFilters(grid, field, operator, value) {
var newFilter = { field: field, operator: operator, value: value };
var dataSource = grid.data("kendoGrid").dataSource;
var filters = null;
if ( dataSource.filter() != null){
filters = dataSource.filter().filters;
}
if ( filters == null ) {
filters = [newFilter];
}
else {
var isNew = true;
var index = 0;
for(index=0; index < filters.length; index++) {
if (filters[index].field == field) {
isNew = false;
break;
}
}
if ( isNew){
filters.push(newFilter);
}
else {
filters[index] = newFilter;
}
}
dataSource.filter(filters);
}
I have tried this solution to call a function on the DataBound event but when the user clears the filter and then tries to group or set other filters, this filter reappears. I am using Razor syntax in the view and was hoping there would be something to set there.
Update: For the time being, I have wrapped the example function in an if on a class level variable that is set to true/false based on if it has been called before but I feel like this is a primitive solution.
function onDataBind(grid, field, operator, value){
if(!alreadyFiltered) //class level variable that is set to true after dataSource.filter(filters);
updateSearchFilters(grid, field, operator, value);
}
}