Sorting on only leaf task

I want to display only leaf tasks in sorted order after clicking on a column heading without any hierarchy using javascript.
I tried all possible ways but it shows hierarchy sorting of leaf tasks. Is there a solution to this problem?

Hello Kavisha,
You need to use a custom sorting function:
https://docs.dhtmlx.com/gantt/desktop__sorting.html#programmaticsorting
https://docs.dhtmlx.com/gantt/desktop__sorting.html#customsortingfunctions
Then you need to attach it to the grid column header by modifying the label parameter in the column configuration:
https://docs.dhtmlx.com/gantt/api__gantt_columns_config.html

If you don’t want to see some tasks, you can hide them with the onBeforeTaskDisplay event handler:
https://docs.dhtmlx.com/gantt/api__gantt_onbeforetaskdisplay_event.html

Here is an example of how it can be implemented:
http://snippet.dhtmlx.com/5/26e42be85

If you need something different, please, describe your question in more detail. You can also send me a picture of how you imagine it should work.

I created object of only leaf task and I want to sort only this new object which I created for leaftask and displayed only that values which are in new object but DHTMLX gantt take gantt object with all task by default so sorting is not accorting to my expactation so is there any way that I can use my object for sorting?

Hello Kavisha,
Gantt sorts the tasks in the chart, not custom objects. To sort a custom object, you need to use the Javascript’s sort function:

If you want to sort tasks in a specific object, you need to remove the existing tasks and load the tasks from the object. Then you can sort tasks and save them in a new object with the getTaskByTime or serialize methods:
https://docs.dhtmlx.com/gantt/api__gantt_gettaskbytime.html
https://docs.dhtmlx.com/gantt/api__gantt_serialize.html
After that, you can load previous tasks.

If you want to sort only specific tasks and ignore other tasks, you will need to create a custom sorting function and pass it to the gantt.sort method:
https://docs.dhtmlx.com/gantt/desktop__sorting.html#customsortingfunctions
Here is an example of how it can be implemented:
http://snippet.dhtmlx.com/5/d543b8046