This is in relation to a DataSource in a Kendo UI Grid that does server side filtering to an OData v4 service.
I know the solution to my problem, I just don't know how to get the DataSource to implement it. How can I force the query that ends up going to the OData service to not include the time portion of a date? Is there a method I can implement that will allow me to modify the URL just before the http get is performed?
When I apply a filter with the type set to "is equals to" the get request for the service looks like this.
https://localhost/Application?$filter=(DOB eq 1997-01-27T00:00:00+00:00)
If I could just get the DataSource to request this instead...
https://localhost/Application?$filter=(DOB eq 1997-01-27)
My problem would be solved. Anyone know how I can resolve this? Thanks!
7 Answers, 1 is accepted
I can suggest using the transport.parameterMap property of the DataSource. This will allow you to modify the parameters before sending it to the remote server. The filter criteria will be available from the data.filter object:
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.parameterMap
I hope this will help to achieve the desired result.
Regards,
Stefan
Telerik by Progress
That looks very promising but when I experimented with it the URL parameters being sent to the service changed from OData to something else. Even something as simple as this...
parameterMap:
function
(data, type) {
return
data;
}
Changes the parameters from this OData query...
$format=json&$top=10&$filter=(FundingPeriodId eq 15 and StudentDOB eq 1997-01-27T00:00:00+00:00)&$count=true
...to...
https://localhost/api/v1/applications/collegeclothingallowance/odata/vwApplication?take=10&skip=0&page=1&pageSize=10&filter[logic]=and&filter[filters][0][field]=FundingPeriodId&filter[filters][0][operator]=eq&filter[filters][0][value]=15&filter[filters][1][field]=StudentDOB&filter[filters][1][operator]=eq&filter[filters][1][value]=Fri Jan 29 1982 00:00:00 GMT-0600 (Central Standard Time)
Any ideas?
I meant to remove the URL portion of the second query for clarity. The result after applying the parameterMap function is...
take=10&skip=0&page=1&pageSize=10&filter[logic]=and&filter[filters][0][field]=FundingPeriodId&filter[filters][0][operator]=eq&filter[filters][0][value]=15&filter[filters][1][field]=StudentDOB&filter[filters][1][operator]=eq&filter[filters][1][value]=Fri Jan 29 1982 00:00:00 GMT-0600 (Central Standard Time)
As you can see it looks nothing like the OData style parameters my service expects to see.
Side Note: I'm not a fan of OData. If there's alternative that works well with your Kendo UI components and C# / Web API 2.2 / Entity Framework 6 I'd really like to know more. Thanks!
PS:
I forgot to remove the URL from the example of what happens when I add the parameterMap code. It should have been...
take=10&skip=0&page=1&pageSize=10&filter[logic]=and&filter[filters][0][field]=FundingPeriodId&filter[filters][0][operator]=eq&filter[filters][0][value]=15&filter[filters][1][field]=StudentDOB&filter[filters][1][operator]=eq&filter[filters][1][value]=Fri Jan 29 1982 00:00:00 GMT-0600 (Central Standard Time)
Also, I don't particularly like OData but it was the only thing I could find that would work with the Grid and easily allow for server side filtering, sorting, etc. using Web API 2.2 and Entity Framework 6. If you have something that would convert those non-OData query parameters into Entity Framework filters I'd be very interested in learning more!
I can suggest checking the following forum thread explaining that when a custom parameterMap is used, this overrides the built-in one which is serialising the parameters correctly. After the needed modifications are finished, you can manually serialise it to the format expected from the oData service:
http://d585tldpucybw.cloudfront.net/forums/parametermap-fails-when-filter-defined
Let me know if you need additional assistance on this matter.
Regards,
Stefan
Telerik by Progress
Rewriting the code to convert the filters to OData queries is more work than I'm willing to do. I'll just ask the users to use date ranges.
Thank you for your assistance.