jQWidgets Forums

jQuery UI Widgets Forums Scheduler How do I get date range of Scheduler

This topic contains 6 replies, has 4 voices, and was last updated by  Martin 4 years, 7 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • How do I get date range of Scheduler #89375

    yougotnet
    Participant

    How can I retrieve the from and to from the Scheduler?

    How do I get date range of Scheduler #89387

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    How do I get date range of Scheduler #89403

    yougotnet
    Participant

    But the viewChange event doesn’t fire when the Scheduler is loaded and it doesn’t fire when navigating next and previous month.

    How do I get date range of Scheduler #89410

    Peter Stoev
    Keymaster

    Hi yougotnet,

    There are other Scheduler events, too. Please, look at the widget’s API.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    How do I get date range of Scheduler #113311

    calculuswhiz
    Participant

    This 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.

    How do I get date range of Scheduler #113327

    calculuswhiz
    Participant

    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);
    
    How do I get date range of Scheduler #113390

    Martin
    Participant

    Hello calculuswhiz,

    Thank you for your contribution!

    Best Regards,
    Martin Yotov

    jQWidgets team
    https://www.jqwidgets.com

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.