get current date range of calendar

Matt SonesMatt Sones ✭✭
edited August 2018 in Questions
Is there a way I can get a calendar component's current date range?

Comments

  • MWSMWS
    edited December 2017
    This would be excellent to know also :)
  • edited December 2017
    Matt,

    Would something like this work?  I added a button to a calendar page to run this script.

    This was built in Skuid 11.0.3.  The calendar filter conditions may have different names in earlier versions.

    Thanks,

    Bill


    var params = arguments[0],
        $ = skuid.$;

    var ev=skuid.model.map().Events;

    var cons = ev.conditions;

    console.log(cons);

    var start, end;

    for (i = 0; i < cons.length; i++) {
        console.log(cons[i].name);
        if (cons[i].name.includes('startlimit')) {
            start = cons[i].value;
        }
        if (cons[i].name.includes('endlimit')) {
            end = cons[i].value;
        }
    }

    console.log('Start value-> ' + start);
    console.log('End value-> ' + end);

  • Matt SonesMatt Sones ✭✭
    edited December 2017
    Thanks, Bill.

    When skuid doesn't have a canned method, do it by brute force!
  • Matt SonesMatt Sones ✭✭
    edited August 2018
    Quick update on this code.

    Since the event models seem to have the calendar date range conditions at the end, we'll start looping through the conditions at the end instead of the beginning, and stop as soon as we have both start and end.

    var model = skuid.$M('TargetModel'),
        cons=skuid.$M('EventModel').conditions,
        start, end, i = cons.length - 1;
    while (i >= 0 && (!start || !end)) {
        if (cons[i].name.includes('startlimit')) {
            start = cons[i].value;         model.setCondition(model.getConditionByName('start'),start);
        }
        if (cons[i].name.includes('endlimit')) {
            end = cons[i].value;         model.setCondition(model.getConditionByName('end'),end);
        }
        i--;
    }

    model.updateData();
Sign In or Register to comment.