-
Notifications
You must be signed in to change notification settings - Fork 147
Specifying Initial Search Values
Datatables provides the option to define an initial search for individual columns. Documentation for this feature is available on the Datatables web site at https://datatables.net/reference/option/searchCols
mvc.jquery.datatables uses the jquery.dataTables.columnFilter plugin to provide extended filtering capabilities.
Append your initial search values to the .FilterOn method. A third parameter accepts an anonymous type to specify search values. The "sSearch" field is required, and the "bEscapeRegex" is optional.
Search fields can be set to an individual string, or be "~" separated in the case of range values. Any values are case sensitive.
NOTE: If using initial search values, then you must set StateSave to false. This is a current limitation in Datatables, where you cannot have saving of state and setting initial values at the same time.
vm
.FilterOn("Position", new { sSelector = "#custom-filter-placeholder-position" }, new { sSearch = "Tester" }).Select("Engineer", "Tester", "Manager")
.FilterOn("Id", null, new { sSearch = "2~4", bEscapeRegex = false }).NumberRange()
.FilterOn("IsAdmin", null, new { sSearch = "False" }).Select("True","False")
.FilterOn("Salary", new { sSelector = "#custom-filter-placeholder-salary" }, new { sSearch = "1000~100000" }).NumberRange();
vm.StateSave = false;
aoSearchCols = searchCols, in the upgrade to Datatables v1.10, the option was changed from "aoSearchCols" to "searchCols" (as well as "sSearch" -> "search" and "bEscapeRegex" -> "escapeRegex". The setting "aoSearchCols" is still valid in v1.10, and to be consistent with the existing settings used by mvc.jquery.datatables, the v1.9 setting value has been used.