[]
FlexGrid supports filtering for column entries, which is enabled through ICollectionView interface. It allows you to apply Condition filters and Value filters to the grid. This makes it easy for you to fetch the desired entries from the data in your grid.
Use Filter by Condition to apply conditions to narrow down your search, and Filter by Value to precisely locate data corresponding to the desired column value. Ascending and Descending buttons enable you to sort the entries in a particular column in ascending and descending order respectively.
The following image shows how the FlexGrid appears after applying Filter by Value to different columns. The example uses Sale.cs model added in the Quick Start section. Here, you create filters for different columns in the grid, and specify conditions or provide exact values to refine your search. Click Apply to fetch the filtered values.

The following image shows how the FlexGrid appears on applying Filter by Condition.

The following code examples demonstrate how to enable Filtering in the FlexGrid:
FilterController.cs
public ActionResult Filter()
{
return View(Sales.GetData(15));
}Filter.cshtml
@using MVCFlexGrid.Models
@using C1.Web.Mvc.Grid
@model IEnumerable<Sale>
@(Html.C1().FlexGrid<Sale>()
.Id("filteringGrid")
.AutoGenerateColumns(false)
.Bind(Model)
.IsReadOnly(true)
.Columns(columns =>
{
columns.Add(column => column.Binding("ID"));
columns.Add(column => column.Binding("Start"));
columns.Add(column => column.Binding("End").Format("t"));
columns.Add(column => column.Binding("Country"));
columns.Add(column => column.Binding("Product"));
columns.Add(column => column.Binding("Color"));
})
.Filterable(f => f.DefaultFilterType(C1.Web.Mvc.FilterType.Both))
.CssClass("grid")
)Property | Type | Values | Description |
|---|---|---|---|
show-include-selection | Boolean | true / false | true: Displays Include Current Selection option in the filter panel. false: Hides Include Current Selection option. |
The MultiFilter feature allows FlexGrid to apply Condition and Value filters simultaneously on the same column.
FlexGrid supports this functionality through the defaultFilterMode property, which uses the FilterMode enumeration. The following filter modes are available:
SingleFilter
MultiFilter
By default, FlexGrid uses SingleFilter, which allows only one filter type at a time. To enable both Condition and Value filters simultaneously, set the defaultFilterMode property to MultiFilter.
The following sample demonstrates how to enable the MultiFilter feature.
public ActionResult Filter()
{
return View(Sales.GetData(15));
}@using MVCFlexGrid.Models
@using C1.Web.Mvc.Grid
@model IEnumerable<Sale>
@(Html.C1().FlexGrid<Sale>()
.Id("filteringGrid")
.AutoGenerateColumns(false)
.Bind(Model)
.IsReadOnly(true)
.Columns(columns =>
{
columns.Add(column => column.Binding("ID"));
columns.Add(column => column.Binding("Start"));
columns.Add(column => column.Binding("End").Format("t"));
columns.Add(column => column.Binding("Country"));
columns.Add(column => column.Binding("Product"));
columns.Add(column => column.Binding("Color"));
})
.Filterable(f => f
.DefaultFilterType(FilterType.Both)
.DefaultFilterMode(FilterMode.MultiFilter)
)
.CssClass("grid")
)FlexGrid supports custom search behavior for Value Filters.
By default, the Value Filter search box uses standard text matching. To define custom matching logic, set SearchType to Custom and assign a JavaScript callback through the CustomFilter property.
Custom filtering is applied only to the Value Filter search box and does not affect Condition Filter behavior.

The custom filter callback receives the entered search text and the current filter item. The callback returns true when the item should be included in the filtered list.
The following example splits the search text by & and verifies that each term is present in the item text. For example, entering Can&da matches Canada.
Controller
The following example defines the custom callback and configures the Country column with a custom Value Filter.
public ActionResult Filter()
{
return View(Sales.GetData(15));
}ASP.NET MVC View
The following example defines the custom callback and configures the Country column with a custom Value Filter.
@using MVCFlexGrid.Models
@using C1.Web.Mvc.Grid
@model IEnumerable<Sale>
<script type="text/javascript">
function customValueFilter(filterText, filterItem) {
var itemText = filterItem.text.toLowerCase();
var searchTerms = filterText.toLowerCase().split('&');
return searchTerms.every(function (term) {
return itemText.indexOf(term.trim()) > -1;
});
}
</script>
@(Html.C1().FlexGrid<Sale>()
.Id("filteringGrid")
.AutoGenerateColumns(false)
.Bind(Model)
.IsReadOnly(true)
.Columns(columns =>
{
columns.Add(column => column.Binding("ID"));
columns.Add(column => column.Binding("Start"));
columns.Add(column => column.Binding("End").Format("t"));
columns.Add(column => column.Binding("Country"));
columns.Add(column => column.Binding("Product"));
columns.Add(column => column.Binding("Color"));
})
.Filterable(f => f.DefaultFilterType(FilterType.Both)
.ColumnFilters(cfsb =>
{
cfsb.Add(cfb => cfb.Column("Country")
.FilterType(FilterType.Value)
.ValueFilter(vfb =>
{
vfb.SearchType(ValueFilterSearchKind.Custom)
.CustomFilter("customValueFilter");
}));
})
)
.CssClass("grid")
)Reference