I have grid with datasource of 15000 rows, where one page has 1000 rows. All filters always show checkboxes with all unique rows, even after i use filtration on grid and decrease row number. I want use excel-like filtering: when i use one filter in column on grid, then other column filters also refresh and show only unique values from current filtered grid.
I found example from telerik for this (.Examples.Mvc/Telerik.Examples.Mvc/Areas/GridFilterExcelLike), but it has a problem. It shows only unique values from grid.datasource.view(). It means it shows unique values in filter from one current page, and not uses other pages.
How can i can modify this example, so filters always show unique values from all grid?
Grid and DataSource:
@(Html.Kendo().DataSource<Telerik.Examples.Mvc.Areas.GridFilterExcelLike.Models.GridFilterExcelLikeProduct>()
.Name("dataSourceShared")
.Ajax(dataSource => dataSource
.Read(read => read.Action("Products_Read", "Home"))
.ServerOperation(false)
)
)
@(Html.Kendo().Grid<Telerik.Examples.Mvc.Areas.GridFilterExcelLike.Models.GridFilterExcelLikeProduct>()
.Name("grid")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Products_Read", "Home"))
.PageSize(20)
.Events(events => events
.Change("onChange")
)
)
.Events(events => events
.FilterMenuInit("onFilterMenuInit")
)
.Columns(columns =>
{
columns.Bound(product => product.ProductID).Filterable(ftb => ftb.Multi(true).DataSource("dataSourceShared"));
columns.Bound(product => product.ProductName).Filterable(ftb => ftb.Multi(true).DataSource("dataSourceShared"));
columns.Bound(product => product.UnitsInStock).Filterable(ftb => ftb.Multi(true).DataSource("dataSourceShared"));
columns.Bound(product => product.UnitPrice).Filterable(ftb => ftb.Multi(true).DataSource("dataSourceShared"));
})
.Pageable()
.Filterable()
.Sortable()
)
Script from example:
<script>
function onChange(e) {
dataSourceShared.data(e.items);
}
function onFilterMenuInit(e) {
var grid = e.sender;
e.container.data("kendoPopup").bind("open", function () {
dataSourceShared.sort({ field: e.field, dir: "asc" });
var uniqueDsResult = removeDuplicates(grid.dataSource.view(), e.field);
dataSourceShared.data(uniqueDsResult);
})
function removeDuplicates(items, field) {
var getter = function (item) { return item[field] },
result = [],
index = 0,
seen = {};
while (index < items.length) {
var item = items[index++],
text = getter(item);
if (text !== undefined && text !== null && !seen.hasOwnProperty(text)) {
result.push(item);
seen[text] = true;
}
}
return result;
}
}
</script>
And Datasource action
public ActionResult Products_Read([DataSourceRequest] DataSourceRequest request)
{
using (var northwind = new GridFilterExcelLikeEntities())
{
IQueryable<GridFilterExcelLikeProduct> products = northwind.Products;
DataSourceResult result = products.ToDataSourceResult(request);
return Json(result);
}
}