1

I am able to display my contents in the bootstrap-treeview, able to modify few things i.e., restricting selection up to only one node.by using below dirty solution,

if(editId!='') {
                $($checkableTree).treeview('uncheckAll', { silent: true });
                $($checkableTree).treeview('checkNode', [ node.nodeId, { silent: true } ]);
}

Problem I want to pre-checked a node at the time of edit, issue is I don't have the nodeId, I have only href record information.

please view below screen shot. enter image description here

I have taken below documentation for reference but no luck, https://www.jqueryscript.net/other/Dynamic-Tree-View-Plugin-jQuery-Bootstrap.html

if someone know that how to do this please help.

Kamran Sohail
  • 602
  • 7
  • 13

1 Answers1

1

Well I am able to resolve my issue,

Below was the solution,

<script>
if(editId!='') 
{   
            selectNodeById(editId); // this function to get the node Id to make checked
            checkvals = parseInt(document.getElementById('editid_node').value); 
            $($checkableTree).treeview('checkNode', [ checkvals, { silent: true } ]);
            $('#checkable-output').prepend('<p>' +checkvals + ' was checked</p><div style=""><input type="checkbox" name="arr[]" checked id="check_'+checkvals+'" value="'+node.href+'"></div>');

}

function selectNodeById(id)
{
    var treeViewObject = $('#treeview-checkable').data('treeview'),
    allCollapsedNodes = treeViewObject.getCollapsed(),
    allExpandedNodes = treeViewObject.getExpanded(),
    allNodes = allCollapsedNodes.concat(allExpandedNodes);
    for (var i = 0; i < allNodes.length; i++) {

        console.log(allNodes);
        if (allNodes[i].href != id) continue;
        document.getElementById('editid_node').value = allNodes[i].nodeId;
    }
}
</script>
  <html>  
  <input type="hidden" name="editid_node" id="editid_node" value="">
</html>
  • selectNodeById($editId) to get the nodeId from href, in my case href is unique

  • editid_node is a hidden file were I assigned the nodeId

  • checkvals = parseInt(document.getElementById('editid_node').value); used to checked the required node.

Kamran Sohail
  • 602
  • 7
  • 13