We have an websocket event handler that sends messages when entities have updated, and we would like to react on these events by invalidating/refetching data fetched by using the requestData handler. What's the best way to do this? I've tried using
projectModel.load()
, but that seem to be tied to CRUDManager as it reports "Trying to request without URL specified".
Ideally, it would be as simple as
projectModel.invalidate({ events: [id1, id2] })
, and it would trigger a new requestData that asks for updating these specific ids, but I'm happy with whatever you have available now.
To handle websocket events and refresh specific data in your SchedulerPro setup, you can use the requestData function to manually trigger data fetching for specific records. Unfortunately, there isn't a direct invalidate method as you described, but you can achieve similar functionality by manually updating the store data.
Here's a general approach:
Listen for websocket events and determine which records need updating.
Use the requestData function to fetch the updated data for those specific records.
Update the store with the new data.
For example, you can implement a function that handles the websocket event and updates the store:
function handleWebsocketEvent(updatedIds) {
const store = schedulerpro.eventStore;
store.requestData({ ids: updatedIds }).then(newData => {
newData.forEach(record => {
const existingRecord = store.getById(record.id);
if (existingRecord) {
existingRecord.set(record);
}
});
});
}
This approach assumes your backend can handle requests for specific IDs and return the updated data.
If you need more control, consider using the requestData event to intercept and customize data fetching logic.
More generally about refreshing data - we also have a refresh button as well that should basically clean the store and trigger a new lazy load based on the current view. How would I best perform this? I tried to call projectModel.eventStore.load() as well, but that then triggers an error saying "Unknown identifier ModelClass-1985.$.assignmentsByCalendar" for some reason.
To refresh the data in the store and trigger a new lazy load, you can clear the store and then use the requestData function to fetch the data again. Here's a general approach:
Clear the store using store.removeAll().
Use requestData to fetch the data based on the current view.
Here's an example:
function refreshData() {
const store = schedulerpro.eventStore;
store.removeAll(); // Clear the store
// Trigger a new lazy load based on the current view
store.requestData({ startDate: schedulerpro.startDate, endDate: schedulerpro.endDate }).then(newData => {
store.add(newData); // Add the new data to the store
});
}
This approach assumes your backend can handle requests for the current view's date range and return the appropriate data.
If you still have the error you mentioned, please provide a minimal test case for us to debug and check what's causing the issue.
To refresh the data in the store and trigger a new lazy load, you can clear the store and then use the requestData function to fetch the data again. Here's a general approach:
Clear the store using store.removeAll().
Use requestData to fetch the data based on the current view.
Here's an example:
function refreshData() {
const store = schedulerpro.eventStore;
store.removeAll(); // Clear the store
// Trigger a new lazy load based on the current view
store.requestData({ startDate: schedulerpro.startDate, endDate: schedulerpro.endDate }).then(newData => {
store.add(newData); // Add the new data to the store
});
}
This approach assumes your backend can handle requests for the current view's date range and return the appropriate data.
If you still have the error you mentioned, please provide a minimal test case for us to debug and check what's causing the issue.
Thanks, but I don't think this is quite equivalent, as scheduler.startDate and scheduler.endDate represents the start and end of the buffer and is thus a much larger span than the startDate and endDate being sent on a regular lazy loaded requestData request, right? Is there a way to get the same startDate and endDate as being used for lazy loading the current visible range?