Server Filtering: How to get the next start and end date when navigating

8 posts, 0 answers
  1. Ben
    Ben avatar
    8 posts
    Member since:
    Nov 2017

    Posted 19 Feb Link to this post

    I'm using the scheduler with server filtering and I'm trying to get the next start date & end date of the scheduler view but i can't figure it out.

    i'm not using ASP/C# so i need a JS example of how to do this. Every example i've found has just linked to a visual studio project, which is no good for me.

  2. Tyler
    Tyler avatar
    68 posts
    Member since:
    Feb 2017

    Posted 20 Feb in reply to Ben Link to this post

    Do you mean you want the next set of dates after the current view you are on stored somewhere? Or do you want the set of dates you are currently moving to when a user navigates?

    You can get the next view start by using e.date in the navigate event.

    Otherwise, you can get the correct view start and end in the dataBinding event with e.sender.view().startDate() and e.sender.view().endDate().

  3. Ben
    Ben avatar
    8 posts
    Member since:
    Nov 2017

    Posted 20 Feb in reply to Tyler Link to this post

    yeah, i need the set of dates the user is moving to when they navigate.

     

    Using e.date doesn't provide you with the "whole view" as you can see a number of days from the following month. So if i were to navigate from Jan to Feb (month view), the first 10 days of march are also included.

     

    databinding also doesnt work, just tried it and when navigating from Feb to March (month view) it provided the following date range:

     

    Start Date: 2018-02-25T00:00:00.000Z(correct)

    End Date: 2018-04-06T23:00:00.000Z (wrong)

    In the actual view, it also includes 07-04-2018.

     

    So if i were to send the CRUD request based on this range, the users would not see events on the 7th of April in march, which they should because it's in the view.

  4. Tyler
    Tyler avatar
    68 posts
    Member since:
    Feb 2017

    Posted 20 Feb in reply to Ben Link to this post

    Are you modifying the end datetime of the view at any point... it seems like you might be, as you should be getting a zeroed time. I just did this on my scheduler, my dataBinding gave me:

    Start Date: Sun Feb 25 2018 00:00:00 GMT-0600 (Central Standard Time)

    End Date: Apr 07 2018 00:00:00 GMT-0500 (Central Daylight Time)

     

    The end date should not have any hours on it, neither should the start. It could be your modifications to the end date are changing it to be incorrect.

  5. Ben
    Ben avatar
    8 posts
    Member since:
    Nov 2017

    Posted 20 Feb in reply to Tyler Link to this post

    No i've not modified the end date at all. Maybe a bug?

    It also caused a problem calling the dataSource.read() in the dataBinding event as it would enter an infinite loop. The the dataBinding event would call the read method, which would in turn call the dataBinding method... etc etc..  maybe i'm doing something wrong here?

    I have coded around it now by doing something a bit hacky but it works for now. I feel like you should be able to get the next view range from the navigate event... This seems the most logical thing to me.

  6. Tyler
    Tyler avatar
    68 posts
    Member since:
    Feb 2017

    Posted 20 Feb in reply to Ben Link to this post

    Yes, getting the next range from navigate would be ideal, but I had to work in the dataBinding for the same reason: controlling amount of events read into the scheduler based on the current view. 

    If you are reading in the dataBinding, then you need a flag. I have a freshlyRead flag. In the navigate event, I set it to 0 (new stuff is not read and needs to be), so then if freshlyRead is 0 in the dataBinding, set it to 1 (it is now read), call out to my server, get my events, read them in with dataSource.read(), and it won't do this again since freshlyRead is 1. Flags are commonly used, not entirely 'hacky'.

    But there shouldn't be a but with e.sender.view().endDate() in dataBinding. Event looking at their demo on their site it gives the correct zeroed out date. You are not trying to set it to midnight or 11 or anything, or trying to correct for a timezone offset?

  7. Ben
    Ben avatar
    8 posts
    Member since:
    Nov 2017

    Posted 20 Feb in reply to Tyler Link to this post

    Nope, this is the first I've even gone anywhere near startDate, endDate. Nothing else in my code touches them. 

    I have no idea why my its being weird. Maybe I'm cursed. 

    And yeah it only just crossed my mind to use a flag in dataBinding. Sometimes the simple solutions don't always present themselves in my mind. 

    the way im doing it is using the JS date library to get the first and last day of the month in e.date (in the navigate event) and then just adding 10 days to the last day of the month and subtracting 10 days from the first day of the month. That covers all the month views and their overlapping dates.

    i will end up receiving back some "unseen" data but it won't be a lot and I doubt it'll noticbly affect performance.

     

  8. Tyler
    Tyler avatar
    68 posts
    Member since:
    Feb 2017

    Posted 20 Feb in reply to Ben Link to this post

    That isn't necessarily a bad way to do it depending on how you are querying things.

    My database allows an event to be up to 14 days long at the most. So I take my starting view date - 14 days, and my ending view date + 14 days in my query because I still want to see partial events if they started or end outside of the current view. 

Back to Top