Bootstrap-treeview doesn't expand or collapse

6.7k views Asked by At

Here is my html file.

 <head>
       <meta charset="utf-8" />
       <meta http-equiv="X-UA-Compatible" content="IE=edge">
       <title>Pimba na Bulita</title>
       <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

       <!-- FontAwesome -->
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">

       <!-- Bootstrap -->
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous"/>

       <!-- My custom Css -->
       <link rel="stylesheet" type="text/css" media="screen" href="assets/css/main.css" /> 

       <!-- TreeView -->
       <link rel="stylesheet" type="text/css" href="assets/bootstrap-treeview/dist/bootstrap-treeview.min.css">
    </head>
    <body>
       <div class="col-md-6" align="center">            
          <span>List of Recent records</span>
          <div id="tree"></div>
       </div>  
        <!-- JQUERY -->
        <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
         crossorigin="anonymous"></script>

        <!-- Bootstrap JS -->
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>  


         <!-- TreeView -->
         <script src="./assets/bootstrap-treeview/dist/bootstrap- 
         treeview.min.js"></script>
    </body>

And here is my js file where I initialize the bootstrap-treeview.

$(document).ready(function() {
    var tree = [
      {
        text: "Parent 1",
        nodes: [
          {
            text: "Child 1",
            nodes: [
              {
                text: "Grandchild 1"
              },
              {
                text: "Grandchild 2"
              }
            ]
          },
          {
            text: "Child 2"
          }
        ]
      },
      {
        text: "Parent 2"
      },
      {
        text: "Parent 3"
      },
      {
        text: "Parent 4"
      },
      {
        text: "Parent 5"
      }
    ];

    $('#tree').treeview({data: tree});
});

As you guys can see below. The problem is: For some reason it's not possible to expanding/collapse the tree.

Detail: If I remove the css refenrece from the file. It does not make any difference ! enter image description here

Why is this happening and how to fix it?

3

There are 3 answers

0
Alexey Trofimov On

The problem is in bootstrap version. As far as ive found out v4 is not supported.

To make your tree work change BS imports on v3:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

I am now looking for BS v4 solution and digging in this:

http://gijgo.com/tree
0
Phi Nguyen On

you can change in boostrap-treeview:

expandIcon: 'fa fa-plus',
collapseIcon: 'fa fa-minus'

---don't forget include:

<link href="https://pro.fontawesome.com/releases/v5.10.0/css/fontawesome.css" rel="stylesheet">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
1
Andrew On

The problem seems to be stemming from Bootstrap4's dropping of the Glyphicons font. My solution was to edit the bootstrap-treeview.js file of the developer branch on the project's github so that the default icons specified on lines 36-42 are as follows:

expandIcon: 'fa fa-plus-square-o',
collapseIcon: 'fa fa-minus-square-o',
emptyIcon: '',
nodeIcon: '',
selectedIcon: '',
checkedIcon: 'fa-check-square-o',
uncheckedIcon: 'fa fa-square-o',

Make sure to link to the fontawesome5 CDN in your application