shinobukawano / Ext.ux.AccordionList

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

addrecords handler is not correct - fix posted here #42

Open drbsoftware opened 9 years ago

drbsoftware commented 9 years ago

I don't think the "addrecords" event handler is correct. fixTreeStoreSortOrder just plain does not work when the inserted record is NOT the first child.

This seems to work in Sencha Touch 2.3.1 to rebuild the "all" list and the items "list".

        store.on('addrecords', function (store, records) {
            // fix sort order if we add children to a already loaded treestore
            var all = [];
            var expanded = [];
            addNodes(all, store.getRoot());
            addExpanded(expanded, store.getRoot());
            store.getData().all = all;
            store.getData().items = expanded;

            function addNodes(arr, node) {
                var childNodes = node.childNodes;
                for (var i = 0; i < childNodes.length; i++) {
                    arr.push(childNodes[i]);
                    addNodes(arr, childNodes[i]);
                }
            }
            function addExpanded(arr, node) {
                var childNodes = node.childNodes;
                for (var i = 0; i < childNodes.length; i++) {
                    arr.push(childNodes[i]);
                    if (childNodes[i].get("expanded")) {
                        addExpanded(arr, childNodes[i]);
                    }
                }
            }
        });

Should do the same for "removerecord" events.

After adding all the records, I also had to do a

store.updateNode(store.getRoot())