How to select a cell in the grid? (like gantt.selectTask(id))

I have enabled keyboard navigation:

gantt.config.keyboard_navigation_cells = true;

Selecting a task is simple, just use

gantt.selectTask(id);

But now I would need to programmatically select a cell in the grid. I couldn’t find anything in the documentation for this, any ideas?

Hello Frederik,
You can use the following command to change the focus:

gantt.ext.keyboardNavigation.focus{type:"taskCell", id:"task id", column:"column name"}

But that will work only if the focus is already on the Grid. You need to use a delay to after changing the focus.
The following example shows how it might work:
http://snippet.dhtmlx.com/689d096b7

We’ll update the following article and mention that it is possible to specify the task cell in the focus() method:
https://docs.dhtmlx.com/gantt/api__gantt_ext_other.html

Very nice, thanks.

And sorry, I didn’t realize that I also needed a way to get the currently selected column. Is that also possible?

Hello Fredrik:
There is no built-in method in the current version, but it will be added in the next version (6.1).
Now, you can use the internal method to get the current active cell:

gantt.$keyboardNavigation.dispatcher.getActiveNode()

Here is the snippet:
http://snippet.dhtmlx.com/e9a32b720

Excellent, thank you!

Hello Fredrik,
The dev team implemented a new function that returns the active cell:

gantt.ext.keyboardNavigation.getActiveNode()

Here is an example:
http://snippet.dhtmlx.com/a889c6e9c

Unfortunately, the documentation doesn’t mention that change, but we will add it in the future.

2 Likes