shinobukawano / Ext.ux.AccordionList

Accordion List Component for Sencha Touch 2
http://kawanoshinobu.com/public/demo/accordionlist/
50 stars 28 forks source link

Load child nodes when expanding the node and the children are not loaded #27

Closed Odi55555 closed 10 years ago

Odi55555 commented 10 years ago

I want to fix #26. After some debugging and comparison to the nested list code I had to remove the onNodeBeforeExpand override. Because this function checks if the children of a node are loaded or not. The treestore loads the node's children for us, if they're not loaded.

The next problem was the sort order. The treestore adds the new records at the end of its data and items array. This is not a problem for a nestedlist, because it creates a new list store for every tree layer. However the AccordionList has only one list and displays the items in the same order like they're stored at the items array of the treestore. Every time a node is expanded the node's children are added to the items array from the data array and vice versa when a node is collapsed.

In my opinion there's a bug at sencha's add method for a treestore, because it tries to add the new records at the right index, but it fails at the insertAll method of Ext.util.Collection. This method gets the correct index for the data array, but not for the items array where it inserts the new records. Because the index is too high (data array length > items array length, if not every node is expanded), it calls the addAll method. This method just pushes the new records add the end of the array and insertAll is skipped. I just added an addrecords listener and fix the sort order if necessary.

My other commits are just fixing some jshint errors and beautifying the code.

shinobukawano commented 10 years ago

Wow, Excellent work!! Actually, I didn't know the dynamic loading ability of TreeStore.. I merge your update and it seems working very well! I want to create an example of dynamic loading with the server side program within several days.

I am also impressed your solution of the sort order problem.. I found this problem but I couldn't fix it elegantly.

Thank you very much!! :D

Odi55555 commented 10 years ago

I'm glad I could help. Looking forward to check out the new example :)