javascriptextjs4.2

How to expand or collapse all rows using the ExtJs rowexpander?


I have seen other similar questions answered, but I cannot get any of the solutions to work. For instance, one solution was to count the records in the grid and loop through calling expandRow(rowNumber) for each one. However, the rowexpander that I am using in ExtJs 4.2 does not have this function.


Solution

  • I figured out a solution to this:

    expandAll: function (expand) {
        expand = typeof expand !== 'undefined' ? expand : true;
    
        var grid = this,
            store = grid.getStore(),
            rowExpander = grid.plugins[0],
            nodes = rowExpander.view.getNodes();
    
        for (var i = 0; i < nodes.length; i++) {
            var node = Ext.fly(nodes[i]);
    
            if (node.hasCls(rowExpander.rowCollapsedCls) === expand) {
                rowExpander.toggleRow(i, store.getAt(i));
            }
        }
    },
    

    I am guessing that the selection of the plugin is not the proper way to do so, but I do not know the proper way.