Premium support for our pure JavaScript UI components


Post by jimmycallin »

Hi!

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.

Thanks!


Post by marcio »

Hey jimmycallin,

Thanks for reaching out.

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:

  1. Listen for websocket events and determine which records need updating.
  2. Use the requestData function to fetch the updated data for those specific records.
  3. 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.

Let me know if you need further assistance!

Best regards,
Márcio

How to ask for help? Please read our Support Policy


Post by jimmycallin »

Thanks! That makes sense.

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.


Post by marcio »

Hey jimmycallin,

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:

  1. Clear the store using store.removeAll().
  2. 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.

Best regards,
Márcio

How to ask for help? Please read our Support Policy


Post by jimmycallin »

marcio wrote: Thu Apr 24, 2025 6:26 pm

Hey jimmycallin,

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:

  1. Clear the store using store.removeAll().
  2. 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?


Post by marcio »

Hey jimmycallin,

You're correct. For visible range, we have https://bryntum.com/products/scheduler/docs/api/Scheduler/view/TimelineBase#property-visibleDateRange, which provides the current visible date range.

This should ensure that you're fetching data for the currently visible range, similar to how lazy loading operates.

Let me know if this helps or if you need further assistance!

Best regards,
Márcio

How to ask for help? Please read our Support Policy


Post by jimmycallin »

fyi, reloading with projectModel.load() should now be supported since this issue: https://github.com/bryntum/support/issues/11171


Post Reply