Better select all method

Hi!

I’ve done some method to select all tasks showed by the Gantt, but when programatically select each task, and the amount of task is over 100, it takes some seconds to “paint” each task.

handleSelectAll = () => {
    for (const t in visibility) {
        visibility[t] && ganttInstance.selectTask(t)
    }
}

So, is there any way to optimize a “select all tasks” function?

Thanks!

Hello @aibarr,
As I don’t see your code, I can’t suppose how you can modify it. Anyway, it takes some time to loop through tasks, and it can take longer in cases with many tasks.

As a possible solution, I can suggest you to loop through the tasks using ‘gantt.eachTask()’ method, which shows some delay from 500+ tasks.
Also, if it’s just a “UI” issue, you can do some trick:
Select only visible tasks on the screen, by default there something like ± 20 tasks, so the selection should be very fast.
and after then call the next function, which will select all loaded tasks, the code may look like this fragment:

 function customSelectAll(){
  gantt.eachTask(function(task){
      gantt.selectTask(task.id);
  })
}
 function selectVisible(){
  gantt.eachTask(function(task){
    if (gantt.getTaskRowNode(task.id)) {
      gantt.selectTask(task.id);
    }
  })
}

function stepSelection(){
  selectVisible();
  gantt.message("Visible tasks are selected")
  setTimeout(()=>{
    customSelectAll();
  },2000)
}

Here is a demo with 500 tasks, where you can try these methods:
http://snippet.dhtmlx.com/suite5/snippet/8b879512c