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
741 stars 278 forks source link

Setting attribute data-tt-parent-id is explicit when adding child node #147

Open wimrijnders opened 10 years ago

wimrijnders commented 10 years ago

Hereby an issue which has kept me busy for quite a while.

When using method treetable() to dynamically add a new child under a given node, I was expecting that the parent id of the child node would be set within the call. However, I discovered by trial and error I had to set it explicitly.

Eg. I had to do the folowing; given a new row definition in $(new_row):

// Determine the parent node from a given id
var parent_node = $('#tree_table').treetable("node", parent_id);

// Explicitly set the parent id
$(new_row).attr('data-tt-parent-id', parent_id);  // !!! Superfluous !!!

// Add new node to parent
$('#tree_table').treetable("loadBranch", parent_node, new_row);

If you don't do this, the new node will be added as a top node.

Since the parent_node is explicitly specified, having to explicitly set the data-tt-parent-id attribute should not be necessary. The necessary info has already been passed by means of parameter parent_node.