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

Remove Time from OData v4 Date Filter

7 Answers 574 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 14 Oct 2016, 03:02 PM

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

Sort by
0
Stefan
Telerik team
answered on 18 Oct 2016, 08:53 AM
Hello Scott,

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
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Scott
Top achievements
Rank 1
answered on 18 Oct 2016, 04:15 PM

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?

0
Scott
Top achievements
Rank 1
answered on 18 Oct 2016, 04:30 PM

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!

0
Scott
Top achievements
Rank 1
answered on 18 Oct 2016, 04:33 PM

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!

0
Scott
Top achievements
Rank 1
answered on 18 Oct 2016, 04:34 PM
And apparently when I click "Post this reply" it errors but then saves my post anyway, so I double posted.  Sorry.
0
Stefan
Telerik team
answered on 20 Oct 2016, 06:32 AM
Hello Scott,

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
 
Build rich, delightful, *native* Angular 2 apps with Kendo UI for Angular 2. Try it out today! Kendo UI for Angular 2 (currently in beta) is a jQuery-free toolset, written in TypeScript, designed from the ground up to offer true, native Angular 2 components.
 
0
Scott
Top achievements
Rank 1
answered on 20 Oct 2016, 01:35 PM

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.

Tags
Data Source
Asked by
Scott
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Scott
Top achievements
Rank 1
Share this question
or