Remove Time from OData v4 Date Filter

8 posts, 0 answers
  1. Scott
    Scott avatar
    17 posts
    Member since:
    Aug 2015

    Posted 14 Oct Link to this post

    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!

  2. Stefan
    Admin
    Stefan avatar
    265 posts

    Posted 18 Oct Link to this post

    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.
     
  3. Kendo UI is VS 2017 Ready
  4. Scott
    Scott avatar
    17 posts
    Member since:
    Aug 2015

    Posted 18 Oct in reply to Stefan Link to this post

    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?

  5. Scott
    Scott avatar
    17 posts
    Member since:
    Aug 2015

    Posted 18 Oct in reply to Scott Link to this post

    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!

  6. Scott
    Scott avatar
    17 posts
    Member since:
    Aug 2015

    Posted 18 Oct in reply to Scott Link to this post

    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!

  7. Scott
    Scott avatar
    17 posts
    Member since:
    Aug 2015

    Posted 18 Oct in reply to Scott Link to this post

    And apparently when I click "Post this reply" it errors but then saves my post anyway, so I double posted.  Sorry.
  8. Stefan
    Admin
    Stefan avatar
    265 posts

    Posted 20 Oct Link to this post

    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.
     
  9. Scott
    Scott avatar
    17 posts
    Member since:
    Aug 2015

    Posted 20 Oct in reply to Scott Link to this post

    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.

Back to Top
Kendo UI is VS 2017 Ready