Hi,
I have a grid with 2 fields that are connected so a cascade filter needs to be done on them. I manage to do this using Server binding because the UI was refreshed when a filter was done. But now I have to use Ajax binding but the cascade code does not work anymore because the UI is no longer called again
@(Html.Kendo().Grid<TelerikTestModel>() .Name("grid2") .Columns(columns => { columns.Bound(product => product.MainField).UI("mainFilter")); columns.Bound(product => product.DependentField).UI("subFilter")); }) // .Server() .DataSource(dataSource => dataSource.Ajax().PageSize(10).Read(read => read.Action("Data_Read", "Home"))) .HtmlAttributes(new { style = "height: 550px;", @class = "myClass" }) .Pageable(x => x.ButtonCount(5)) .Sortable() .Filterable() .Scrollable() //.ColumnMenu() .Resizable(resize => resize.Columns(true)) .Reorderable(reorder => reorder.Columns(true)) .Events(e => e.FilterMenuInit("filterMenuInit")))
function mainFilter(element) { element.kendoDropDownList({ dataSource: { transport: { read: "@Url.Action("FilterMenuCustomization_MainFilter")" } }, optionLabel: "--Select Value--", name: "mainFilter", }); } function subFilter(element) { var dataSource = $("#grid").data("kendoGrid").dataSource; var filter = dataSource.filter(); var value = -1 if (filter && filter.filters) { var result = $.grep(filter.filters, function (e) { return e.field == "MainField"; }); if (result.length == 1) { value = result[0].value; } } element.kendoDropDownList({ dataSource: { transport: { read: { url: "@Url.Action("FilterMenuCustomization_SubFilter")", dataType: "json", data: { mainFilter: value, } } } }, optionLabel: "--Select Value--", name: "subFilter", }); }Two questions:
1. in subFilter is there a way to get to the grid datasource without using the grid id? I need to make this code be used by any grid that has a dependent list
2. for the Ajax-binding I was thinking to use the onFiltering event but how can I get to the filter control (to do the subFilter code)? On a page with 2 grids and the same dependent cascade filters I could not find a connection between the grid and the filter controls.