chniter / bstreeview

Bootstrap Treeview, A very simple plugin to build a basic and elegant Treeview with bootstrap 4. See the demo:
https://chniter.github.io/bstreeview/
Apache License 2.0
367 stars 53 forks source link

Refresh bstreeview #24

Closed fdelval closed 3 years ago

fdelval commented 3 years ago

Hi, I am just using the plugin retrieven data in json format from a database.

As soon as a user inserts new records in database, I refresh page to see new nodes.

Is there a way to refresh the plugin without reloading the whole page? Something like $('#treeview').bstreeview().reload();

I have read about unbinding events. But I can't figure out how to do it.

Any help would be appreciated. Thank you.

chniter commented 3 years ago

Hi,

For the moment, we can reload treeview data because the treeview don't accept data url to refresh. You can clear the html dom element of treeview and then build it again.

Thanks

bala-sakthis commented 1 year ago

Note: This works in v1.0.0.

Based on the solution provided by @chniter, do the below:

  1. Remove the TreeView element. $('#TreeViewDiv').remove();

  2. Append the TreeView element. $('#ParentDiv').append('<div id="TreeViewDiv"></div>');

  3. Build the TreeView again.

    $('#TreeViewDiv').bstreeview({
    data: JSON.stringify(treeViewData),
    expandIcon: 'fa fa-angle-down fa-fw',
    collapseIcon: 'fa fa-angle-right fa-fw',
    indent: 1.25,
    parentsMarginLeft: '1.25rem',
    openNodeLinkOnNewTab: true
    });