0
votes

I am using a Kendo UI Grid in a ASP.Net MVC5 application and set up a column so that when you go to filter on it it queries the database for the unique results. I define the column like this:

col.Filterable(x => x.Multi(true).Search(true).DataSource(ds => ds.Read(r => r.Action("UniqueColumn", "Workbook").Data("filterUniquenessColumn()").Type(HttpVerbs.Post)).ServerFiltering(true)));

This only calls the controller the first time you go to it because it's cached. To get around this I subscribed to the ColumnMenuInit event and added the following code:

var menu = e.container.find(".k-menu").data("kendoMenu");
menu.bind('open', function (ex) {
    if ($(ex.item).find('span.k-i-filter').length > 0) {
        var filterMultiCheck = e.container.find(".k-filterable").data("kendoFilterMultiCheck");
        if (filterMultiCheck) {

            if ($('#grid').data('kendoGrid').dataSource.filter() !== undefined) {
                var grid = $('#grid').data('kendoGrid');
                filterMultiCheck.checkSource.transport.options.read.data.filter = grid.dataSource.filter();                    
                filterMultiCheck.checkSource.options.type = 'aspnetmvc-ajax';
            }
            filterMultiCheck.checkSource.read();
        }
    }
});

This calls the controller every time they go to filter (which is what I want). The problem I am having is that on the controller side I am unable to get the Filters value of the [DataSourceRequest] DataSourceRequest request to be populated with the filters that are applied to the main grid. The result for Filters is always null. This is what my controller method looks like:

        public ActionResult UniqueColumn([DataSourceRequest] DataSourceRequest request)

Does anyone know how I can get the filters property of the request to be populated? I put a trace on the network and the following is being passed via the url:

filter%5Bfilters%5D%5B0%5D%5Bfield%5D: PCode filter%5Bfilters%5D%5B0%5D%5Boperator%5D: eq filter%5Bfilters%5D%5B0%5D%5Bvalue%5D: 00090h4210 filter%5Blogic%5D: and

If anyone could tell me how to get the filters on the controller it would be greatly appreciated.

Thanks in advance.

2

2 Answers

3
votes

In case this is helpful for anyone integration kendo jQuery UI + .net core 2.0+, was able to resolve this by including the kendo.aspnetmvc js file in my application and setting the DataSource.type = "webapi".

Link: https://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/binding/web-api-server-operations

For background on my project: Server: .NET Core 2.2 Client: aurelia SPA (js), typescript

0
votes

In case anyone else has this issue I was able to solve it by doing the following:

        if ($('#grid').data('kendoGrid').dataSource.filter() !== undefined) {
                    var grid = $('#grid').data('kendoGrid');
                    var parameterMap = grid.dataSource.transport.parameterMap;
                    var dataRequest = parameterMap({
                        sort: grid.dataSource.sort(),
                        filter: grid.dataSource.filter(),
                        group: grid.dataSource.group(),
        } 

var request = decodeURIComponent($.param(dataRequest));                        
filterMultiCheck.checkSource.transport.options.read.url = "/Workbook/UniqueColumn" + "?" + request;