Sort tasks ignoring the filltered (parent) tasks

I have a Gantt chart with filtered parent tasks using the “onBeforeTaskDisplay” event.

I am trying to figure out a way how to sort the currently visible tasks without respect to the parent tasks.

Hello Nikolai,
You need to use a custom sorting function:
https://docs.dhtmlx.com/gantt/desktop__sorting.html#customsortingfunctions
And it will affect only the child tasks whether their parent tasks are visible or not.
Here is an example of how it might be implemented:
http://snippet.dhtmlx.com/a06d36f0a

@ramil,

actually the snippet has something like a bug. Currently, it is hiding task21 and task22. When I modified it:

gantt.attachEvent("onBeforeTaskDisplay", function(id, task){
    if (!toggle) return true;
    if (task.parent == 10 || task.parent == 20){
        return true;
    }
    return false;
});

now it doesn’t hide task21 && task22 and you can clearly see that they (task21 and task22) are not sorted along with all the child tasks but their sort state is based on their parent task.

What I need is a way to sort the child tasks as if there is no parent tasks!

Let me know please if there is any solution.

10x in advance.

Hello Nikolai,
Thank you for the clarification. Actually, Gantt sorts the same way.
The way you want to sort tasks requires changing the task parent.
Notice what happens when you manually reorder tasks:
https://files.dhtmlx.com/30d/2f7afad7ac36d12d946fa5c44c8f9351/vokoscreen-2019-11-29_11-42-37.avi

There is no way to change that logic, you need to implement a custom solution. For example, you can save the original parent in a parameter, change the parent parameter, filter tasks and sort them under the same parent. When you remove the filter, you move the tasks to the original parent.
Here is an example of how it might be implemented:
http://snippet.dhtmlx.com/313ffed99

this approach works.

however most users will find it more natural if the gantt sorts (or has additional parameter in the sort method) the tasks based on their current visibility.

Hello Nikolai,
Thank you for the clarification. I will forward your suggestion to the dev team.