I use Grid.MVC to show my data to user. I need to setup initial column filtering for column "active" after page loads first time.
I read document page of Grid.MVC and it says i should add .SetInitialFilter() to the column but it does not work for me. If you have any idea, please let me know it
@Html.Grid(Model).Named("MVCGrid").Columns(columns =>{
columns.Add(e => e.id).Titled("id");
columns.Add(e => e.usernumber).Titled("user number");
columns.Add(e => e.active).Titled("active").SetInitialFilter(GridFilterType.Equals, "true");
columns.Add(e => e.manager).Titled("manager");}).WithPaging(28).Filterable().WithMultipleFilters().Sortable().WithGridItemsCount()
The
SetInitialFilter
is used for setting an initial value based on the content. This method will not set the initial filter in itself what you are trying to do.In order to set the initial filter, you need to make change to the source
gridmvc.js
file. Under thetextFilterWidget.prototype.onRender
, change thevalue
from:this.value = values.length > 0 ? values[0] : { filterType: 1, filterValue: "" };//1 stands for Equals filter
to
this.value = values.length > 0 ? values[0] : { filterType: 2, filterValue: "" };//2 stands for Contains filter
Once you make this change, the default filter will now be
Contains