Skip to main content

Is there a way I can get a calendar component’s current date range?

This would be excellent to know also 🙂


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 = consci].value;

}

if (consci].name.includes(‘endlimit’)) {

end = consdi].value;

}

}


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

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


Thanks, Bill.

When skuid doesn’t have a canned method, do it by brute force!


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 (consni].name.includes('startlimit')) {
start = consni].value; model.setCondition(model.getConditionByName('start'),start);
}
if (consni].name.includes('endlimit')) {
end = consni].value; model.setCondition(model.getConditionByName('end'),end);
}
i--;
}

model.updateData();```