Problem in the template "task_cell_class"

Hi,

I am facing a problem with the template changes “task_cell_class” because as mention in the doc we can normally get the task item associated to the row where the cell is but the type of the object item is “Date” and because of that I can not directly get the task object of the row where the cell is.
(Refer to this doc: docs.dhtmlx.com/gantt/api__gant … plate.html)

For the moment, the only way I found to get the task item is to iterate on all tasks objects of the gantt and synchronise the global index of the task with the number of row where the cell is with a counter.

I am now doing that :

            var number_of_displayed_tasks = gantt.getVisibleTaskCount();
            
            tasks.forEach(element => {
                var t = <Task> element;
                let number_of_column = 16;
                if(t.is15)
                    number_of_column = 16;
                else
                    number_of_column = 31;

                console.log(Math.trunc(t.compteur/number_of_column));

                if(Math.trunc(t.compteur/number_of_column) == gantt.getGlobalTaskIndex(t.id))
                {
                    if(t.parent)                
                        isParent = false;               
                    else              
                        isParent = true;                          
                }    

                t.compteur++;
                //console.log(gantt.getVisibleTaskCount());
                // Initialisation des compteurs si atteint la fin
                if(t.compteur == number_of_displayed_tasks*number_of_column)
                {
                    t.compteur = 0;
                }       

But as you can see it is very costly to iterate on each task of the gantt on each cell…because of that there are some lag when I load a big amount of tasks. So I am asking myself if it is possible to get an update of dhtmlx gantt where we can directly get the task item of the row of the cell when we try to change the template of a cell of the timeline.

Thanks in advance.

Hi,

You can compare dates when target task occur with date parameter.

for(var i=0; i<item.duration; i++){ var targetDate = gantt.date.add(item.start_date, i, 'day'); if(date.getDate() == targetDate.getDate()){ ... } }

docs.dhtmlx.com/gantt/snippet/4d6e4b47

But here you just test if the cell’s date is between the start_date and the end_date of the task. My problem is a little bit different, because I realy need to get the entire task object of the row where the cell is. Because I applied some css for the parent task and some css for the child task and in the futur I will maybe want to color some cell according to some variable of the task object.

I don’t fully understand your issue. Entire task object is ‘item’. Is this not what you need?

That’s exactly the problem because as you can see in the document, the type of the object “item” is “Date” and not “any” because of that I can not access directly to the “Task” object.

Actually it is task object, not date. Check typeof item in console.
We will correct type on the page with template info in API ASAP.

It is not only in that doc page, it is also in the type file for typescript (I have attached a screen).
And I have also noticed that the return type of the function getGlobalIndex is not correct too, it should return a number but in the type file it is said that it returns nothing, so we have to change it manually in the type file each time a new developper install the type of dhtmlx gantt (I have also attached a screen for that).
Please try to change it for the next update of type file.

Thanks in advance.



Thank you, we’ll update it.