jQWidgets Forums
jQuery UI Widgets › Forums › Scheduler › How do I get date range of Scheduler
Tagged: scheduler from date
This topic contains 6 replies, has 4 voices, and was last updated by Martin 4 years, 7 months ago.
-
Author
-
How can I retrieve the from and to from the Scheduler?
Hi yougotnet,
viewChange event when raised has such information. Otherwise, the Scheduler’s date property retrieves the current Date in the Scheduler.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comBut the viewChange event doesn’t fire when the Scheduler is loaded and it doesn’t fire when navigating next and previous month.
Hi yougotnet,
There are other Scheduler events, too. Please, look at the widget’s API.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThis isn’t too helpful an answer. The OP asked for a range.
You have to add to the date you get from the ‘date’ property:
function getSchedulerRange($scheduler) { let baseDate = $scheduler.jqxScheduler('date'); let view = $scheduler.jqxScheduler('view'); let toDate; switch(view) { case 'dayView': toDate = baseDate.addDays(1); break; case 'weekView': toDate = baseDate.addDays(7); break; case 'monthView': toDate = baseDate.addMonths(1); break; case 'agendaView': toDate = baseDate.addDays(7); break; // Add more cases here... default: toDate = baseDate.addDays(7); break; } return ( { from : baseDate.toDate(), to : toDate.toDate() }); } // Call the function: getSchedulerDateRange($('#scheduler-element'));
I guess they forgot to add this property accessor in.
Oops, I the answer I gave before wasn’t correct for a few reasons:
1. The view property doesn’t change when the buttons are pressed. (This one’s not my fault.)
2. The base date defaults to today, not the beginning of the date range.
3. The base date will not change when the range view is changed.A more “reliable” way to do this would be to use the status bar’s date information at the top of the scheduler:
function getSchedulerRange($scheduler) { let statusTexts = $scheduler // Grab the status bar: .find('.jqx-scheduler-toolbar-details') .text() .split(' - '); return ( { // Convert to Date object from : new Date(statusTexts[0]), // Account for single-day view to : new Date(statusTexts[statusTexts.length - 1]) }); }
Of course, this still could have all been avoided if they had given us a property accessor or a getter method to retrieve this info. But, hey, what can you do? (Bother it all and make one yourself with React, perhaps.)
Also, as per usual with these widgets, the status bar will not be valid immediately in the context of your event listener. In this case, you can defer the function call until the currently executing context is done executing like so:
// Standard jqWidgets timer hack setTimeout(function () { // Do things with the data here... getSchedulerRange($('#scheduler-element')); }, 0);
Hello calculuswhiz,
Thank you for your contribution!
Best Regards,
Martin YotovjQWidgets team
https://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.