Getting date for week_unit_scale_text template


#1

Hi

I’m using week_unit view and I’d like the column of every unit to show the number of events in that column. I’ve already used getEvents() to populate an array of counts for each date/resource combination. I can use that array to show the count in day view and in week view using the scale_text template. But in week_unit view, I can’t figure out how to determine the date of the current column.

This is the code I’m using:
scheduler.templates.week_unit_scale_text = function(key, label, unit) {
if (x.resource_count_unit[date_format(scheduler.getState().date)]) {
return label + ': ’ + “” + x.resource_count_unit[date_format(scheduler.getState().date)][key] + “”;
}

return true;
};

Of course, the getState.date() is using the date for the beginning of the week, not for the column in question.

Thank you for your support.


#2

Hi,

To get the date of the target cell, you can use {view_name}_second_scale_date template that described in the article https://docs.dhtmlx.com/scheduler/units_view.html#displayingunitsformultipledays

Check the console in the snippet, there you can see how to get the required date in the week_unit_scale_text template. http://snippet.dhtmlx.com/82b74b515


#3

That looks like it’s almost doing what I need. Strangely, the log looks OK, but if I return the date you generated as part of the template, it’s one day off.

All I changed in the snippet is to “return targetWeekUnitDate” in the scale_text:
http://snippet.dhtmlx.com/a7cccc2c8


#4


#5

Yes, it’s strange. To solve the issue, “return scheduler.date.add(targetWeekUnitDate, 1, ‘day’)” from week_unit_scale_text template
http://snippet.dhtmlx.com/f418c3a88