This is a migrated thread and some comments may be shown as answers.

MVC Grid Cascading Filter Options of a kendoFilterMultiCheck

1 Answer 293 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eddie
Top achievements
Rank 1
Eddie asked on 13 Oct 2015, 03:51 PM

I want my filters to update and only show options that match up with all filters currently applied.

I am working with Year Make Model filters. If I select a year 2004 and apply that filter. I want the Make and Model filters to only show the currently filtered data set options. I should only see Make and Model options that have a year of 2004.

In addition, after the first init call of the filter, i want the options to reload based on the data source. If I add a new car to the data source or remove one, the filter options will re-poll the data source and find those ones removed or added.

 

in http://www.telerik.com/forums/refresh-multi-checkbox-filter-options-when-grid-is-filtered, i found what seems to be a good viable option but only discussed as a Javascript defined grid. I have a MVC HTML Razor implemented grid. Listed below is the soultion I am hoping to retro fit into my MVC application of the grid. 

 

"define one DataSource instance and assign it to both the Grid and in columns.filterable.dataSource. This will refresh the checkbox data automatically, but if you filter the Grid data via the Grid UI, you will also filter (reduce) the checkbox items."

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Oct 2015, 07:10 AM
Hello Eddie,

It is possible to set the grid dataSource instance to the filters via the setOptions method after the grid is initialized:
@(Html.Kendo().Grid<MyModel>()
    .Name("grid")
    .AutoBind(false
    ...
)
 
<script>
    $(function () {
        var grid = $("#grid").getKendoGrid();
        var dataSource = grid.dataSource;
        var options = grid.getOptions();
        var columns = options.columns;
        var column;
        for (var i = 0; i < columns.length; i++) {
            column = columns[i];
            if (column.filterable && column.filterable.multi) {
                column.filterable.dataSource = dataSource;
            }
        }
        options.autoBind = true;
        options.dataSource = dataSource;
 
        grid.setOptions(options);
    });
</script>
however note that if the same instance is used and the dataSource is configured for server operations, the 
data will be reloaded each time a filter menu is initialized.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Eddie
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or