Awfully basic JavaScript treeview component.

Overview

simple-treeview

Awfully basic JavaScript treeview component.

Usage

Vanilla Tree View

  • Include the treeview CSS:
<link rel="stylesheet" href="https://unpkg.com/simple-treeview/dist/treeview.vanilla.css">
  • If you want to use Font Awesome icons, include its CSS as well:
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous">
  • Load the treeview JavaScript (as an ES module), and use the VanillaTreeView class:
<script type="module">
    import { VanillaTreeView } from 'https://unpkg.com/simple-treeview/dist/treeview.vanilla.js';
    let tree = new VanillaTreeView(document.getElementById('tree'), {
        provider: {
            async getChildren(id) {
                if (!id) {
                    return [
                        { id: 'p1', label: 'Parent #1', icon: { classes: ['far', 'fa-folder'] }, state: 'collapsed' },
                        { id: 'p2', label: 'Parent #2', icon: { classes: ['far', 'fa-folder'] }, state: 'expanded' }
                    ];
                } else {
                    await new Promise((resolve, reject) => setTimeout(resolve, 1000)); // Simulate 1s delay
                    switch (id) {
                        case 'p1':
                            return [
                                { id: 'c1', label: 'Child #1', icon: { classes: ['far', 'fa-file'] }, state: 'collapsed' },
                                { id: 'c2', label: 'Child #2', icon: { classes: ['far', 'fa-file'] } }
                            ];
                        case 'p2':
                            return [
                                { id: 'c3', label: 'Child #3', icon: { classes: ['far', 'fa-file'] } },
                                { id: 'c4', label: 'Child #4', icon: { classes: ['far', 'fa-file'] } }
                            ];
                        case 'c1':
                            return [
                                { id: 'g1', label: 'Grandchild #1', icon: { classes: ['far', 'fa-clock'] } }
                            ];
                        default:
                            return [];
                    }
                }
            }
        }
    });
</script>

Bootstrap Tree View

  • Make sure you include Bootstrap dependencies (incl. Bootstrap Icons if you want to use those, too), for example:
<!-- CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<!-- JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
  • Include the treeview CSS:
<link rel="stylesheet" href="https://unpkg.com/simple-treeview/dist/treeview.bootstrap.css">
  • Load the treeview JavaScript (as an ES module), and use the BootstrapTreeView class:
<script type="module">
    import { BootstrapTreeView } from 'https://unpkg.com/simple-treeview/dist/treeview.bootstrap.js';
    let tree = new BootstrapTreeView(document.getElementById('tree'), {
        provider: {
            async getChildren(id) {
                if (!id) {
                    return [
                        { id: 'p1', label: 'Parent #1', icon: { classes: ['bi', 'bi-folder'] }, state: 'collapsed' },
                        { id: 'p2', label: 'Parent #2', icon: { classes: ['bi', 'bi-folder'] }, state: 'expanded' }
                    ];
                } else {
                    await new Promise((resolve, reject) => setTimeout(resolve, 1000));
                    switch (id) {
                        case 'p1':
                            return [
                                { id: 'c1', label: 'Child #1', icon: { classes: ['bi', 'bi-file-earmark'] }, state: 'collapsed' },
                                { id: 'c2', label: 'Child #2', icon: { classes: ['bi', 'bi-file-earmark'] } }
                            ];
                        case 'p2':
                            return [
                                { id: 'c3', label: 'Child #3', icon: { classes: ['bi', 'bi-file-earmark'] } },
                                { id: 'c4', label: 'Child #4', icon: { classes: ['bi', 'bi-file-earmark'] } }
                            ];
                        case 'c1':
                            return [
                                { id: 'g1', label: 'Grandchild #1', icon: { classes: ['bi', 'bi-clock'] } }
                            ];
                        default:
                            return [];
                    }
                }
            }
        }
    });
</script>
You might also like...

Awesome books app is a basic website that allows users to add/remove books from a list. It is a single page app (SPA) which allow switching to different pages of the app without page load. Built with JavaScript.

Awesome Books ES6 In this project, I build a basic website that allows users to add/remove books from a list. using ES6 syntax and make it more organi

Jul 1, 2022

In this project, I built a basic website that allows users to add/remove books from a list using HTML/CSS to build the app and JavaScript to add functionalities. This project was organized using modules and ES6 syntax implemented.

Awesome books: with ES6 Description the project. Built With HTML CSS JAVASCRIPT Live Demo (if available) Live Demo Link Getting Started This is an exa

Sep 9, 2022

A simple todo list app written in javascript and html with basic CSS styling This project makes use of webpack to bundle the code. I implemented 3 functionalities on the this project namely: Add task edit task delete task using Js

My To-Do List A simple todo list app written in javascript and html with basic CSS styling This project makes use of webpack to bundle the code. I imp

Nov 11, 2022

This is a basic app that allows user add/remove books from a list of books. It was created by using JavaScript arrays and objects to dynamically modify the DOM.

Awesome-Books This application lets you compile a dynamic collection of books using JavaScript. It is a single page app. You enter your book title & a

Oct 24, 2022

The new BASIC computer that runs in your browser!

The new BASIC computer that runs in your browser!

atto The new BASIC computer that runs in your browser! Try it live: jamesl.me/atto What is atto? atto is a virtual fantasy computer system that's desi

Dec 29, 2022

This repository contains a basic example on how to set up and run test automation jobs with CircleCI and report results to Testmo.

CircleCI test automation example This repository contains a basic example on how to set up and run test automation jobs with CircleCI and report resul

Dec 23, 2021

Math Calc is a simple algebra calculator with options for basic addition, subtraction, multiplication, and division as well as many more mathematical properties.

Math Calc is a simple algebra calculator with options for basic addition, subtraction, multiplication, and division as well as many more mathematical properties.

Math-Calc Math Calc is a simple algebra calculator with options for basic addition, subtraction, multiplication, and division as well as many more mat

Dec 25, 2021

Node-cli-starter - Basic starter kit for building Node CLI applications with TypeScript.

node-cli-starter Minimal starter kit for building Node CLI applications with TypeScript. Getting Started To get started clone repo locally and run npm

May 17, 2022
Owner
Petr Broz
Forge Developer Advocate @ Autodesk.
Petr Broz
This project will be a basic website that allows users to add/remove books from a list. The main objective is to understand how to use JavaScript objects and arrays and dynamically modify the DOM and add basic events.

Awesome-books Awesome Books This project will be a basic website that allows users to add/remove books from a list. This project is part of the Microv

Aleksandra Ujvari 10 Oct 3, 2022
Basic website that allows users to add/remove books from a list. Achieved using JavaScript objects and arrays, dynamically modifying the DOM and adding basic events.

Awesome Books Basic website that allows users to add/remove books from a list. Achieved using JavaScript objects and arrays, dynamically modifying the

Didier Peran Ganthier 6 Dec 20, 2022
BASIC is a web application contains basic applications related to studies, love, health, weather, productivity. This project aim to simply the user's life in anyway.

BASIC is a web application contains basic applications related to studies, love, health, weather, productivity. This project aim to simply the user's life in anyway. Supported by all operating system, need an internet connection for working properly.

IRUTHAYA SANTHOSE I 1 Dec 19, 2021
This simple project, show how work with async Fetch, function component and class component

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

DaliyaAsel 2 Feb 17, 2022
dynamic-component-app is an angular application for dynamic component template creation

MyApp This project was generated with Angular CLI version 14.1.0. Development server Run ng serve for a dev server. Navigate to http://localhost:4200/

Aniket Muruskar 7 Aug 26, 2022
This is Basic calculator. This is made up of HTML5,CSS and JAVASCRIPT.

<title>BasicCalculator</title> <style> @media screen and (max-width : 574px){ h2{ font-size: large; }} @media screen and (max-width : 430px){ h2{ font

Sanjay soni 1 Dec 22, 2021
A simple leaderboard project made while a student in Microverse using API to get scores for a game, JavaScript, HTML and basic CSS

A simple leaderboard project made while a student in Microverse using API to get scores for a game, JavaScript, HTML and basic CSS

Thiago Ponce 6 Nov 28, 2022
Use javascript and css to build a StreetFighter Ryu,walk,jump,basic punch kick,launch fireball and dragon punch.

SFRyu Use javascript and css to build a StreetFighter Ryu,walk,jump,basic punch kick,launch fireball and dragon punch. 因為小時候就很喜歡玩快打旋風,於是用Javascript,CS

null 21 Sep 1, 2022
Awesome Books. In this project, I built a basic website that allows users to add/remove books from a book list. This project is build with JavaScript.

Event Page Awesome Books. In this project, I built a basic website that allows users to add/remove books from a book list. Built With HTML CSS JavaScr

Miftah Amin 16 Feb 28, 2022
This is an Awesome books page, a basic website that allows users to add and remove books from a list. Built with JavaScript.

Aweasome-books This is our Awesome books page, a basic website that allows users to add/remove books from a list. Built With CSS HTML JavaScript Live

Santiago Cárdenas 6 May 11, 2022