Premium support for our pure JavaScript UI components


Post by marasoft@netrom.ro »

Hello,

I have the following issue, when updating the event store the state object is not updated, bellow you have the code:


scheduler.current.schedulerInstance.eventStore.removeAssignmentsForResource(resource);
  crewMemberSchedules.forEach(item => {
    const color = state.statuses.find(f => f.statusId === item.crewMemberStatu.id).color;
    scheduler.current.schedulerInstance.eventStore.addAsync({ name: item.statusName,
      resourceId: item.crewMemberID,
      draggable: true,
      resizable: true,
      startDate: new Date(item.startDate),
      endDate: new Date(item.endDate),
      eventColor: state.statusIndex === ONBOARD_INDEX ? new Date(item.startDate) < Date.now()
     && new Date(item.endDate) > Date.now() ? ONBOARD_COLOR : color : color,
      crewMemberId: item.crewMemberID,
      scheduleId: item.objectId,
      index: state.statusIndex,
      isRecurrence: hasValue(item.recurrenceID),
      recurrenceId: item.recurrenceID,
    }, false);
  });
  scheduler.current.schedulerInstance.eventStore.commit();
  scheduler.current.schedulerInstance.repaintEventsForResource(resource);

In the bryntum scheduler I use the "events" state object to populate the event store as you can see in the picture

Screenshot_779.png
Screenshot_779.png (32.58 KiB) Viewed 619 times

However, when I modify the events store the ui is updated but the state object is not.

Any solution?

Best regards


Post by saki »

I suppose that resources and events are array of objects. These objects are then taken as data for https://bryntum.com/docs/scheduler/#Scheduler/data/EventStore and https://bryntum.com/docs/scheduler/#Scheduler/data/ResourceStore. These stores hold instances of https://bryntum.com/docs/scheduler/#Scheduler/model/EventModel and https://bryntum.com/docs/scheduler/#Scheduler/model/ResourceModel with data populated from resources and events.

In other words this is not a 2 way binding between internal stores and React state. Bryntum components use their own data layer described in guides "Working with data" starting here: https://bryntum.com/docs/scheduler/#Scheduler/guides/data/displayingdata.md


Post by marasoft@netrom.ro »

So is it safe to assign the new event store data to the event state object after modifying the store in order to keep this 2 in sync?


Post by saki »

Assigning new data to the eventStore is still one-way. When you drag an event, for example, startDate and endDate of the event are updated in the corresponding record in the eventStore. Ideally, this is enough because the store can be configured with https://bryntum.com/docs/scheduler/#Scheduler/data/CrudManager that would take care of persisting the data on the server.

If you really need to update an in-memory array you can listen to https://bryntum.com/docs/scheduler/#Core/data/Store#event-update event and you can update your data in the listener.


Post Reply