Here’s Neil,
Here’s my solution. It’s not perfect but it works well for calendar’s full view. It’s only when you switch form a higher view to a smaller one (month>week>day) that it derails, where the table sticks with the last dates. This is due to the calendar view that behaves strangely. But if you refresh, all comes back to normal until you do this again. I will investigate, but for now you’ve something what works.
All you have to do is change the 4 first lines to match your views and fields.
Enjoy,
Normand D.
const CALENDAR_VIEW_ID = 'view_2925';
const TABLE_VIEW_ID = 'view_2926';
const DATE_FIELD = 'field_1210';
const FIELD_NAME = 'Last scan';
$(document).on('knack-view-render.' + CALENDAR_VIEW_ID, function (event, view, data) {
console.log('render view cal', event, view, data);
$('#' + view.key + ' span.fc-button').on('click', function (e) {
console.log('Render view, current_view =', Knack.views[view.key].current_view);
const sdt = new Date(Knack.views[view.key].start_date).toLocaleDateString('en-US');
const edt = new Date(Knack.views[view.key].end_date).toLocaleDateString('en-US');
console.log('sdt =', sdt);
console.log('edt =', edt);
Knack.views[view.key].triggerRecordsRendered();
})
})
$(document).on('knack-records-render.' + CALENDAR_VIEW_ID, function (event, view, data) {
var sdt = new Date(Knack.views[view.key].start_date).toLocaleDateString('en-US');
var edt = new Date(Knack.views[view.key].end_date).toLocaleDateString('en-US');
console.log('render records cal', event, view, data);
console.log('Rec Render, current_view =', Knack.views[view.key].current_view);
var filterObj = [];
if (Knack.views[view.key].current_view === 'agendaDay') {
edt = Date.parse(edt);
edt = new Date(edt - (24 * 3600 * 1000)).toLocaleDateString('en-US');
filterObj = [
{
"field": DATE_FIELD,
"operator": "is",
"value": {
"date": edt,
"time": ""
},
"field_name": FIELD_NAME
}
]
} else {
filterObj = [
{
"field": DATE_FIELD,
"operator": "is after",
"value": {
"date": sdt,
"time": ""
},
"field_name": FIELD_NAME
},
{
"match": "and",
"field": DATE_FIELD,
"operator": "is before",
"value": {
"date": edt,
"time": ""
},
"field_name": FIELD_NAME
}
]
}
const sceneHash = Knack.getSceneHash();
const queryString = Knack.getQueryString({ [`${TABLE_VIEW_ID}_filters`]: encodeURIComponent(JSON.stringify(filterObj)) });
Knack.router.navigate(`${sceneHash}?${queryString}`, false);
Knack.setHashVars();
Knack.models[TABLE_VIEW_ID].setFilters(filterObj); //Set new filters on view's model
Knack.models[TABLE_VIEW_ID].fetch({
success: () => { Knack.hideSpinner(); }
});
})