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

How to access args.filter value in the onBeforeTimeHeaderRender event of DayPilot Scheduler

Asked by Iliah
23 days ago.

I'm working with DayPilot Scheduler and need to filter events in the onBeforeTimeHeaderRender callback function. I need to access the current filter value that was set elsewhere in my application.

In my onEventFilter function, I'm using args.filter successfully:

onEventFilter: (args) => {
  if (Array.isArray(args.filter)) {
    args.visible = args.filter.length === 0 || args.filter.includes(args.e.data.customer);
  } else {
    args.visible = false;
  }
}

However, when I try to use the same filter in onBeforeTimeHeaderRender to calculate filtered sums, I can't seem to access the filter value:

onBeforeTimeHeaderRender: (args) => {
  if (args.header.level === 0 || args.header.level === 1) {
    const events = scheduler.events.forRange(args.header.start, args.header.end);

    // How do I access the same filter that was used in onEventFilter?
    // Is there a way to get args.filter here?

    const sum = events.reduce((acc, event) => acc + event.data.quantity, 0);
    args.header.html = `${args.header.text} ( ${sum.toString()} )`;
  }
}

Is there a way to access the current filter value in the onBeforeTimeHeaderRender event? I need to use the same filter to calculate sums for only the visible events.

Any help would be appreciated. Thanks!

Answer posted by Dan Letecky [DayPilot]
20 days ago.

The filter param is only available in the onEventFilter event handler.

The best way would be to store the filter value in a special variable outside of the Scheduler object. This approach is used for the row filter in the ASP.NET Core Restaurant Table Reservation tutorial - you can take a look at it for an example.

Comment posted by Iliah
20 days ago.

So using scheduler?.events?.Kg is not correct? Although it works

if (!scheduler?.events?.Kg) {
    console.log("onBeforeTimeHeaderRender filter", filter);
    return;
}
var filter = scheduler.events.Kg;
const events = scheduler.events.forRange(args.header.start, args.header.end);

const filteredEvents = Array.isArray(filter) && filter.length > 0
    ? events.filter(e => filter.includes(e.data.customer))
    : events;
var sum = filteredEvents.reduce((acc, filteredEvent) => acc + filteredEvent.data.quantity, 0);
args.header.html = args.header.text + " ( " + sum.toString() + " )";


BRG
iliah

Comment posted by Dan Letecky [DayPilot]
19 days ago.

Don’t use that - it’s an internal property, its name is random and it will change in the future.

New Reply
This reply is
Attachments:
or drop files here
Your name (optional):