Not getting correct index in case of collapsed hierarchy

Discuss issues related to v5.x
Post Reply
User avatar
priya.yadav
Posts: 39
Joined: Tue Mar 26, 2019 12:31 pm

Not getting correct index in case of collapsed hierarchy

Post by priya.yadav » Tue Aug 06, 2019 7:21 am

Hi team,

When the task hierarchy is collapsed I am not getting the correct task count. Could you please let me know if there are such methods which return correct count/index in case of collapse hierarchy?

I am getting task count as 3 whereas there are 6 tasks in total (3 as a child).

Thanks
Attachments
Screenshot
Screenshot
TaskStructure.PNG (26.19 KiB) Viewed 872 times

User avatar
pmiklashevich
Core Developer
Core Developer
Posts: 2579
Joined: Fri Apr 01, 2016 11:08 am

Re: Not getting correct index in case of collapsed hierarchy

Post by pmiklashevich » Tue Aug 06, 2019 10:56 am

We have a private taskStore.getTotalTaskCount() method. But you can achieve the same using only Ext methods:

Code: Select all

var countChildren = function (node) {
    var count = 0;

    node.cascade(function (rec) {
        // to ignore passed node in counting
        if (rec !== node) {
            count++;
        }
    });
    
    return count;
};

countChildren(Ext.first('ganttpanel').taskStore.getRoot());
https://docs.sencha.com/extjs/6.7.0/classic/Ext.data.NodeInterface.html#method-cascade
Pavel Miklashevich - Core Developer

User avatar
priya.yadav
Posts: 39
Joined: Tue Mar 26, 2019 12:31 pm

Re: Not getting correct index in case of collapsed hierarchy

Post by priya.yadav » Tue Aug 06, 2019 8:32 pm

getTotalTaskCount() helps in getting overall count but I have to get index of a particular task which can be anywhere. Counting tasks manually will increase overhead in my case.
In the task structure mentioned in screenshot ,when I am trying to get index of "New Task 7" it is returning 4 if i use taskStore.indexOf() .
Please tell me the use of getIndexInTotalDataset() also.

Thanks
Attachments
Screenshot 2
Screenshot 2
TaskStructure1.PNG (22.02 KiB) Viewed 863 times

User avatar
pmiklashevich
Core Developer
Core Developer
Posts: 2579
Joined: Fri Apr 01, 2016 11:08 am

Re: Not getting correct index in case of collapsed hierarchy

Post by pmiklashevich » Wed Aug 07, 2019 9:43 am

What's your use case? What real problem you're trying to solve?
Pavel Miklashevich - Core Developer

User avatar
priya.yadav
Posts: 39
Joined: Tue Mar 26, 2019 12:31 pm

Re: Not getting correct index in case of collapsed hierarchy

Post by priya.yadav » Wed Aug 07, 2019 11:27 am

Use case :
I am selecting a task (say reference task) and creating N number of tasks from the backend. I have to populate dates on these newly created tasks. In order to achieve that I am getting the index of the task which I had previously selected and then the index of last task being created from the backend. After getting both the indexes I am iterating through tasks and setting dates.

In the context of Screenshot 2:

reference task: New task 7
When I am trying to get the index of reference task with taskStore.indexOf(reference task) it is returning 4 instead of 7 if tasks are collapsed. If I do expand all then I am getting index as 7. In the case of large number of tasks expand all is taking significant time.

I want to know if there is any method which will return me the correct index/sequence number in case of collapsed hierarchy.

User avatar
Maxim Gorkovsky
Core Developer
Core Developer
Posts: 3065
Joined: Wed Jan 08, 2014 11:46 am

Re: Not getting correct index in case of collapsed hierarchy

Post by Maxim Gorkovsky » Fri Aug 09, 2019 1:34 pm

Hello.
It looks like you can refer not the index of the task, which apparently doesn't work like you expect on the collapsed tree, but to the task id.
So instead of storing index of the last selected task, store it's id. That way you could lookup the record. IIRC extjs tree store will return null when you try to get record from the collapsed branch, so try using getModelById

Post Reply