ludo / jquery-treetable

jQuery plugin to show a tree structure in a table
http://ludo.cubicphuse.nl/jquery-treetable
GNU General Public License v2.0
739 stars 278 forks source link

Add option to append nodes at top. [PR request pending] #208

Open Nejaa opened 6 years ago

Nejaa commented 6 years ago

EDIT : See PR request

I had this need lately. I made it work by adding a non core parameter to the options :

_table.treetable({
    expandable: true,
    clickableNodeNames: true,
    onNodeExpand: onNodeExpand,
    prependRootNodes: true //Not a core parameter.
});

Then I modified the loadBranch function like that :

loadBranch: function (node, rows) {
            //...          
            if (node == null) { // Inserting new root nodes
                if (settings.prependRootNodes)
                    this.prepend(rows);
                else
                    this.append(rows);
            } else {
                var lastNode = this.data("treetable").findLastNode(node);
                rows.insertAfter(lastNode.row);
            }
            //...
        }

Of course this isn't the only way to go at it. My first idea was to add a parameter to loadBranch that would tell the function to append at the top only for this load request.

In any cases both options wouyld be nice to have in the core plugin. I hope this is helpfull :)