search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Re-Calculate Totals row when a row is deleted

Asked by AK
2 months ago.

Hi,
I am trying to update the totals row (Scheduler) when a resource is deleted from DP. The totals row updates fine when an event is deleted or a row is added to the DP table. The only issue I am having is that it doesn't update when I remove a row from the DP scheduler table.

I am calculating my totals row by using the onBeforeCellRender function as shown in this link: https://code.daypilot.org/93064/javascript-scheduler-column-summary

Would you know of any function that would help me achieve this? Or maybe I am doing something wrong because it seems like every time I delete a row, dp.events array should be updated as well and maybe then the onBeforeCellRender will update the totals row?

Comment posted by WSJU
2 months ago.

I meant totals of individual columns shown in a row. So when a resource is deleted, the totals would need to be re-calculated based on new set of resources.

Comment posted by WSJU
2 months ago.

Example is shown here for rows but I would like to do it for columns. https://code.daypilot.org/46581/html5-timesheet-javascript-php

Answer posted by Dan Letecky [DayPilot]
2 months ago.

The cells in rows marked with "cellsAutoUpdated: true" will be updated on every change, including a row removal.

You might want to review and update the calculation logic. The tutorial (https://code.daypilot.org/93064/javascript-scheduler-column-summary) uses events.forRange() method to find all events for a range:

var events = dp.events.forRange(args.cell.start, args.cell.end);

The current implementation of events.forRange() returns all events in events.list, regardless of the resource.

To include only events from visible rows, you will need to change the the logic. Example:

let events = [];
dp.rows.all().forEach(r => {
  const eventsFromThisRow = r.events.forRange(args.cell.start, args.cell.end);
  events = events.concat(eventsFromThisRow);
});
New Reply
This reply is
Your name (optional):