2022-04-22

kendoui grid filter serialization problem - from client(jquery) to backend (.net)

the grid filter are serialized in this way

http://localhost:4813//datatablekendo?take=20&skip=0&page=1&pageSize=20&filter%5Blogic%5D=and&filter%5Bfilters%5D%5B0%5D%5Bfield%5D=id&filter%5Bfilters%5D%5B0%5D%5Boperator%5D=eq&filter%5Bfilters%5D%5B0%5D%5Bvalue%5D=6 

this is the parsed view from Chrome DevTools

take: 20
skip: 0
page: 1
pageSize: 20
filter[logic]: and
filter[filters][0][field]: id
filter[filters][0][operator]: eq
filter[filters][0][value]: 6

on the backend side (.NET 6 WebApi)

[HttpGet, Route("datatablekendo")]
public override async Task<IActionResult> GetDatatableKendoAsync([DataSourceRequest] DataSourceRequest request)
{
    return await base.GetDatatableKendoAsync(request);
})

the DataSourceRequest has a property "Filters" thant is always null

(note that the name "Filters" is plural)

on the querystring side the parameters are "filter" singular (inside the array is filters)

this is the grid configuration

$("#ordersGrid").kendoGrid({
                    dataSource: {
                        transport: {                            
                            read: {                                
                                url: url,
                                headers: {
                                    'Authorization': 'Bearer ' + token
                                }                               
                            },
                        },
                        schema: {
                            model: model,
                            data: "data",
                            total: "total"
                        },
                        pageSize: 20,
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true
                    },
                    ...
                    pageable: true,
                    sortable: true,
                    filterable:true                    
                });

EDITED

this is the solution: https://www.telerik.com/forums/datasourcerequest-filters-and-sorts-fields-null-here-is-the-solution#2623809



No comments:

Post a Comment