get current date range of calendar

  • 2
  • Question
  • Updated 3 months ago
  • Answered
Is there a way I can get a calendar component's current date range?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 1 year ago

  • 2
Photo of MWS

MWS

  • 158 Points 100 badge 2x thumb
This would be excellent to know also :)
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
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);
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Thanks, Bill.

When skuid doesn't have a canned method, do it by brute force!
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
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();