GithubHelp home page GithubHelp logo

kamil-lip / bootstrap-vue-treeview Goto Github PK

View Code? Open in Web Editor NEW
43.0 3.0 30.0 151 KB

A treeview component for Bootstrap and Vue.js 2.0+

License: MIT License

Vue 75.63% JavaScript 21.40% HTML 2.97%
bootstrap treeview vue2

bootstrap-vue-treeview's Introduction

A treeview component for Bootstrap and Vue.js 2.0+

Bootstrap-Vue-Treeview Screenshot

Online demo

https://bootstrap-vue-treeview.appdiamond.pl

Features

  • Drag & drop nodes
  • Context menu

Installation

npm install --save bootstrap-vue-treeview

Getting started

Webpack

If you use Webpack bundler (recommended) you can import component and register it locally:

import { bTreeView } from 'bootstrap-vue-treeview'
[...]
components: {
	bTreeView
},

or globally using plugin:

import BootstrapVueTreeview from 'bootstrap-vue-treeview'
Vue.use(BootstrapVueTreeview)

Now you can you the treeview component in your code:

<b-tree-view :data="treeData"></b-tree-view>
export default {
  data() {
    return {
      treeData: [{"id": 2, "name": "Venus" , "children": [{"id": 3, "name": "Neptune"}, {"id": 4, "name": "Stratus"} ] } ]
    }
  }
}

API

TreeView

1. Vue props

Prop Type Description Default value Required
data Array Tree data - Yes
nodeKeyProp String Name of the property containing unique node key "id" No
nodeChildrenProp String Where to look for node children "children" No
nodeLabelProp String Name of the property containing node label "name" No
showIcons Boolean Show/hide icons false No
iconClassProp String Name of the property containing icon class "icon" No
defaultIconClass String Icon class to apply if node has no icon class property null No
prependIconClass String Class to apply to every icon (common to all icons) null No
nodesDraggable Boolean Enable/disable drag & drop feature false No
contextMenu Boolean Enable/disable context menu true No
renameNodeOnDblClick Boolean Enable/disable double click to rename feature true No
contextMenuItems Array of menu items Context menu items [ { code: 'DELETE_NODE', label: 'Delete node' }, { code: 'RENAME_NODE', label: 'Rename node' } ] No

2. Events

Event name Description Parameters
nodeSelect Triggered every time a node is selected/deselected. Check second parameter to verify if the node was selected or deselected TreeNode object, isSelected
contextMenuItemSelect Triggered every time a context menu item was clicked. Context menu item object (see below), TreeNode object

TreeNode

Props and events of the tree node component are not intended to be used directly.

1. Methods

Method name Description Parameters
select Select node -
deselect Deselect node -
expand Expand node (show children) -
collapse Collapse node (hide children) -
toggle Expand/collapse -

Menu item

1. Properties

Property Description
code Code of the menu item. Check this code to know which menu item was clicked.
label Label being displayed for the user

bootstrap-vue-treeview's People

Contributors

ismailarilik avatar kamil-lip avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bootstrap-vue-treeview's Issues

Configuration error in package.json

When trying to do testing with this module using Jest, it fails to find the module. After some digging I figured out why:

Package.json:5 has "main": "dist/treeview.js", so Jest is trying to find that file.

It needs to be changed to "main": "dist/bootstrap-vue-treeview.js",

I have verified that this fixes the problem and Jest can find the module as expected.

Would very much appreciate if you could release an update with this fix.

Props not set

my markup

<b-tree-view prependIconClass="fas" ref="tree" :data="treeData" :showIcons="true" ></b-tree-view>

after mounted

prependIconClass is "" and showIcons is false

Custom icons

Hi,

The component is great, but we would like to change the icons to fit our branding.

Would it be posssible to add a way to customize that? Some slots would do the trick I think, to replace the hardcoded SVG.

                <svg width="12"
                     height="12"
                     @click.prevent="toggle"
                     class="tree-node-icon"
                     v-if="hasChildren">
                    <path d="M2 1 L10 6 L2 11 Z"
                          class="svg-icon"/>
                </svg>

Could be something like that :

    <div  v-if="hasChildren" @click.prevent="toggle">
        <slot name="expand-icon">
                <svg width="12" height="12" class="tree-node-icon">
                    <path d="M2 1 L10 6 L2 11 Z" class="svg-icon"/>
                </svg>
           </slot>
    </div>

Same could be done to allow for a fully custom label icon

Vue is not defined

Treenode.Vue line 246:

if (this.data[this.childrenProp] === undefined) {
     Vue.set(this.data, this.childrenProp, [])
}

returns ReferenceError: Vue is not defined

slice of undefined

Thank you for your great work.

I've got 1 issue:
Error in nextTick: "TypeError: Cannot read property 'slice' of undefined"

app.js:2850 TypeError: Cannot read property 'slice' of undefined
    at VueComponent.createNodeMap (app.js:52695)
    at VueComponent.<anonymous> (app.js:52802)
    at Array.<anonymous> (app.js:2946)
    at flushCallbacks (app.js:2867)
<b-tree-view
   :data="cats"
   :nodesDraggable="false"
   :showIcons="false"
   :contextMenu="false"
   :renameNodeOnDblClick="false"
   :contextMenuItems="[]"
   @nodeSelect="nodeSelect"
></b-tree-view>

This is my data:
image

You know why?
Thanks in advance.

Adds some links to names

Hi,
Is it a way to add a link to a node ?

aka.:

...
export default {
    ...
    methods: {
        getName(item) {
            return `<a href="${item.url}">${item.name}</a>`;
        }
    },
    computed: {
        treeData() {
            let foo = {
                id: 1,
                name: 'Foo',
                url: 'http://www.example.org/'
            };
            let output = [{
                name: this.getName(foo),
                id: foo.id
            }];
            return output;
        }
    }
};

Thanks for your great job !

Cannot find module 'bootstrap-vue-treeview'

Hello,

Where can I find the 1.0.8 version from npm?
I have following error during the import:
Cannot find module 'bootstrap-vue-treeview'

My files inside node_modules:

$ ls node_modules/bootstrap-vue-treeview/dist/
bootstrap-vue-treeview.common.js      bootstrap-vue-treeview.esm.js      bootstrap-vue-treeview.js
bootstrap-vue-treeview.common.js.map  bootstrap-vue-treeview.esm.js.map  bootstrap-vue-treeview.js.map

So I cannot find the main file from package.json:

  ],
  "license": "MIT",
  "main": "dist/treeview.js",
  "maintainers": [
    {
      "name": "kamil-lip",
      "email": "[email protected]"
    }
  ],

When I'm changing main to "dist/bootstrap-vue-treeview.js" it is working fine.

BR,
Adam

Typescript bindings

Can you provide typescript bindings, or i can and submit to you ?
Thanks for you greak work

Expand by default feature request

Is there a way to show all items expanded by default?
A prop for this would be very useful and much appreciated to make it easier.
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.