javascript - Kendo UI Default Grid Filter value -
i trying default kendo ui grid filtered on page load. have column boolean values need display ones "false" on page load allow user see them if 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 solution call function on databound event when user clears filter , tries group or set other filters, filter reappears. using razor syntax in view , hoping there set there.
update: time being, have wrapped example function in if on class level variable set true/false based on if has been called before feel primitive solution.
function ondatabind(grid, field, operator, value){ if(!alreadyfiltered) //class level variable set true after datasource.filter(filters); updatesearchfilters(grid, field, operator, value); } }
updating initial comment answer. essentially, if define datasource filter, define datasource in initial state , user still able change filter using ui/controls normal.
for javascript implementation, might this:
datasource: { // ... other config filter: { field: "yourcolumn", operator: "equals", value: false } }
if using column menu filtering, filter show user change - have defined initial state.
you mentioned using mvc implementation. haven't used helpers before. expect matter of using similar configuration method, point, documentation doesn't seem clear. start here:
http://docs.telerik.com/aspnet-mvc/helpers/grid/configuration#filter
so, maybe ends looking this:
.datasource(datasource => datasource .filter(filters => { filters.add(f => f.yourcolumn).equals(false); }
Comments
Post a Comment