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

Re-init with Force duplicates the expander in the table #203

Open TomWhitson opened 7 years ago

TomWhitson commented 7 years ago

I have a table using an expanderTemplate and when I call refresh as below, I end up with multiple expanders in the row,

//tree table refresh
$('#sheet1').treetable({
    expandable: true, 
    expanderTemplate:'<a href="#"><i class="material-icons">expand_more</i></a>',
    onNodeExpand:updateStriping,
    onNodeCollapse:updateStriping
}, true);
kenjdavidson commented 6 years ago

I had this issue as well, in my case I'm wrapping my TreeTable in a DataTable (not my choice, just something I was stuck with). I have the TreeTable set to force initialization when the DataTable Ajax load completes. The blind addition of the indicator was adding multiple each reload.

I resolved it by adding:

$('.indenter',this.treeCell).remove();

on line 34.

I figured it would be best to remove the old one, and have the regular addition occur since someone may want to change the indenter or expander during the reload (different data may require more). I guess technically the class could be changed from Indenter using the indenterTemplate, so it should probably be parse to get the class.