A multi-select component with nested options support for Vue.js
- Single & multiple select with nested options support
- Fuzzy matching
- Async searching
- Delayed loading (load data of deep level options only when needed)
- Keyboard support (navigate using Arrow Up & Arrow Down keys, select option using Enter key, etc.)
- Rich options & highly customizable
- Supports a wide range of browsers (see below)
- RTL support
Requires Vue 2.2+
It's recommended to install vue-treeselect via npm, and build your app using a bundler like webpack.
npm install --save @riophae/vue-treeselect
This example shows how to integrate vue-treeselect with your Vue SFCs.
<!-- Vue SFC -->
<template>
<div id="app">
<treeselect v-model="value" :multiple="true" :options="options" />
</div>
</template>
<script>
// import the component
import Treeselect from '@riophae/vue-treeselect'
// import the styles
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default {
// register the component
components: { Treeselect },
data() {
return {
// define the default value
value: null,
// define options
options: [ {
id: 'a',
label: 'a',
children: [ {
id: 'aa',
label: 'aa',
}, {
id: 'ab',
label: 'ab',
} ],
}, {
id: 'b',
label: 'b',
}, {
id: 'c',
label: 'c',
} ],
}
},
}
</script>
If you just don't want to use webpack or any other bundlers, you can simply include the standalone UMD build in your page. In this way, make sure Vue as a dependency is included before vue-treeselect.
<html>
<head>
<!-- include Vue 2.x -->
<script src="https://cdn.jsdelivr.net/npm/vue@^2"></script>
<!-- include vue-treeselect & its styles. you can change the version tag to better suit your needs. -->
<script src="https://cdn.jsdelivr.net/npm/@riophae/vue-treeselect@^0.4.0/dist/vue-treeselect.umd.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@riophae/vue-treeselect@^0.4.0/dist/vue-treeselect.min.css">
</head>
<body>
<div id="app">
<treeselect v-model="value" :multiple="true" :options="options" />
</div>
</body>
<script>
// register the component
Vue.component('treeselect', VueTreeselect.Treeselect)
new Vue({
el: '#app',
data: {
// define the default value
value: null,
// define options
options: [ {
id: 'a',
label: 'a',
children: [ {
id: 'aa',
label: 'aa',
}, {
id: 'ab',
label: 'ab',
} ],
}, {
id: 'b',
label: 'b',
}, {
id: 'c',
label: 'c',
} ],
},
})
</script>
</html>
Note: please use a desktop browser since the website hasn't been optimized for mobile devices.
- Chrome
- Edge
- Firefox
- IE ≥ 9
- Safari
It should function well on IE9, but the style can be slightly broken due to the lack of support of some relatively new CSS features, such as transition
and animation
. Nevertheless it should look 90% same as on modern browsers.
You can use this pen to reproduce bugs and then open an issue.
- Fork & clone the repo
- Install dependencies by
yarn
ornpm install
- Check out a new branch
npm run dev
& hack- Make sure
npm test
passes - Push your changes & file a pull request
This project is inspired by vue-multiselect, react-select and Ant Design. Special thanks go to their respective authors!
Some icons used in this project:
- "link" icon made by Smashicons is licensed under CC 3.0 BY
- "spinner" icon from SpinKit is licensed under the MIT License
- "caret" icon made by Dave Gandy is licensed under CC 3.0 BY
- "delete" icon made by Freepik is licensed under CC 3.0 BY
- "checkmark symbol" & "minus symbol" icons made by Catalin Fertu are licensed under CC 3.0 BY
Copyright (c) 2017-present Riophae Lee.
Released under the MIT License.
vue-treeselect's People
Forkers
sagarnaliyapara dewdad rubythonode cuulee vatsal-noovosoft kimthiendung90 itorets tekkostom bitw jdlindu limodou sweethope dagnoferreira 21-guns reg2005 bsor-dev cleverad trendingtechnology cshsh laysrain intactprojects dabernathy89 ezra-obiwale zwq8299174 mednabouli hanchuanchuan kevinbatongbakal insitu-software c527380322 web17077 lkmadushan wsl1107073609 wsb260 owumaro myvueyyyy wangyi7099 wickkidd qingyuxiyue hello523 roelhem mwz1991 lerit saviofreitas garsonzhang zikolach chenymin bosquig misenhower libin1991 iprit delonzhou mikemnd codeandrey zacat bakpa79 mulholland0318 tanxuxu maffoobristol cherishit chengliang1024 luozhonghua tanxuweb usei95 mrjjq gengchao123 rvv-bouvet ymengm sy813 luoft yxmg m-zuro jaimesanz zhoujin123 brantolsen skyformat99 yangbospton cloneothersproject alexin0007 bencekd fsateler liuji-jim vue-mk quantran2603 1072258106 sololance thinhhung bazai lelikdub willvincent florianallainmat vincentchen superkieran yashiroiori liweng reiyou0517 buxoytuxlik zhangzhenling dimitri-koenig lixianglong3210 recastrodiazvue-treeselect's Issues
Update currently selected nodes as ajax data comes in
Currently, if you set the source of the tree before the node information has been received (via ajax), then the id of the node is shown.
1 (unknown)
This is expected since the label data isn't there yet. However, when you open the children of the node, I can see that its pre-selected in the tree area, which is great, but it should also update in the "selected/search area" as soon as you open the parent node and data is loaded.
The problem corrects itself if you un-select the node and re-select the node, which fixes all nodes it has data for.
Hopefully this should be as easy as just calling an update method when we expand the parent.
多次的修改options的值
你好
请问有没有办法重新修改options选项的值,我要多次的去修改,我应该怎么去触发呢
Feature: sublabels / option slots
I would like to customize the options adding a new gray sublabel, like count but with my own text. The best solution would probably be a slot that allows the users of this component to change the labels with our own custom HTML:
<treeselect ...>
<template slot="option" slot-scope="option">
{{option.label}}
...other things i want to customize the label with here...
</template>
</treeselect>
You can provide a default slot implementation as a fallback, so it's a completely backwards compatible change and only adds new functionality.
Feature:增加value绑定类型选择
树形选择组件绑定的value希望可以配置为一个对象数组,每一个对象里面有个isBranch字段说明这个item是leaf还是branch
Add required prop
Please add the required
prop that will add required="required"
to .vue-treeselect__input
.
Unknown custom element: <treeselect> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
Feature Request: search/query-string should search in all parents
What i want to achieve is the ability to search with parents included.
Imagine this list:
- A
- 1
- 2
- 3
- B
- 1
- 2
- 3
If i search for 1
i got 2 matches.
What i want is the ability to search for A 1
and get only 1 result.
I already implemented this feature in my fork and could provide a PR after i updated the docu and the tests.
This is my name for that new prop:
{
name: 'searchNested',
type: 'Boolean',
defaultValue: v('false'),
description: `Set true if the searchquery should search in all parent nodes to. For example Children->Mike will match "ch ke"`,
}
Is this something you want?
Or do you need more info on this?
I would be glad to help you with this amazing useful component!
Documentation misleading
In the documentation @ https://vue-treeselect.js.org/#node the explanation for children
says:
Declares a branch node. Set to empty array for no children options. Set to null for delayed loading.
But in my tests it seems as if you have to set children to undefined
. If children is an empty array you can expand the item and see an error message saying: "No children options"
option无法展示label值,展示空白内容?而且选项箭头位置不居左?
Basic Example not working
Hi,
I am just trying to get the basic example working in my project, I have this in a component file:
<!-- Vue component -->
<template>
<treeselect
v-model="value"
:multiple="true"
:options="source"
/>
</template>
<script>
import Treeselect from '@riophae/vue-treeselect'
export default {
components: { Treeselect },
data: {
value: null,
source: [
{
id: 'node-1',
label: 'Node 1',
children: [
{
id: 'node-1-a',
label: 'Node 1-A',
},
],
},
{
id: 'node-2',
label: 'Node 2',
},
],
},
}
</script>
<style src="@riophae/vue-treeselect/dist/vue-treeselect.min.css"></style>
When I load the page, I get:
Vue warn]: The "data" option should be a function that returns a per-instance value in component definitions.
[Vue warn]: Property or method "source" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
found in
---> <BssTree> at /home/vagrant/code/portal/resources/assets/js/components/bss-tree.vue
<Root>
[Vue warn]: Property or method "value" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
found in
---> <BssTree> at /home/vagrant/code/portal/resources/assets/js/components/bss-tree.vue
<Root>
Vue 2.5.13
Am I doing something wrong?
Mick
能否自定每个节点的信息?
目前看文档每个节点包含:id,label。能否包含其他的信息?能否自定义字段名称?。例如:ID,Name,Icond等。最好把每个节点的信息处理为一个对象,对象里的属性就可以自定了。
text filtering
Hi! nice component!
In the example "Disabling Branch Nodes", if I press "fra", it does not display only the France. The same with other countries also.
issue: disabling specific nodes
Hi,
With some of my controls if you are editing an item in a self referencing tree then I use a tree for selecting the parent. I would like to be able to disable the selection of a child element. So it would be nice if the control allowed the options node array to have a disabled or blocked value that would prevent the selection of that item - but allow any that had the value set to false.
Hopefully thats understandable :)
Many thanks
Jon
Input event emitted when component loads.
It looks like the input event fires immediately.
Is this correct?
Is there a way to find the selected node, without using the event?
问下父data中异步获取option无法绑定到treeselect里,默认设置是可以的
Feature: Tree within the page, not in a search box
Hi. 👋
So, at the moment this wonderful tree is created within a search box, as in you can only see it when you open the search box.
Is it possible to not show a search box and instead to simply display the tree within the page?
It's a lovely feature and I find a lot of the times I really need the tree but want to always show it on the page, rather than hiding behind a search box. 😁
Thanks!
Feature Request: option-select event
Hi.
Great component!
It would be nice to have an event, that can report an exact option id that was clicked. input
doesn't work, because if you have: parent, child1, child2 (selected)
. Than click child1
, input
will report all 3 items & it's unknown if user clicked parent
or child1
.
Thanks.
Treeselect in Bootstrap (3) navbar.
Hi,
I am trying to drop your control into a Bootstrap navbar. (A bit like the search box on Github).
It would be fantastic if it was as easy as this:
https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_navbar_form&stacked=h
Is this something you would be interested in doing? I imagine that other people would also desire this.
Thanks,
Mick
Excuse me, why I had use $.ajax to get options, but `vue-treeselect` not work.
I had use $.ajax to get some result, and bind with :option
.
But vue-treeselect
show me "no options avaliable".
my result's format fits your rules.
element disabled
hello, how can I disable an element??
thanks
How can i define default selected item?
When i need to edit some resource. the treeselect should already have selected a specific value. How can i do this?
Prevent Combining Nodes
Although its a cool feature, is there a way to disable the combining of nodes into the parent node? I would like to keep them all as leaf nodes.
For example on the teaser image on the read me, If you select "Apple, Grapes, Pears" I would like to keep them all as leafs instead of combining them into the "Fruit" parent.
How can I disable this?
Some questions about option of props
Greetings,
The value of my options is initially null, but inside this component I'll change this value through the server. How do I assign values to my options after changing? I found that I can not now show the data to options after the data has been modified.
Thanks so much
我该如何支持vue-treeselect的异步搜索
你好,我需要渲染的数据量会很大,所以需要异步的搜索,我尝试监听Input事件来获取用户输入的值并动态的更改option的值,但是我即使动态的更改opttion的值却成功的渲染最新的option值到组件,请问可以提供一些想法或者方案吗?
events
Hello , first of all , what a great component , i really like the documentation .
i am a beginner in vuejs , could you please help me in the events, i did
vm.$on('input', (value, id) => {
console.log(value, id)
})
but this didn't work , btw i added this in created
Add icon and images
Hi I would like to know how to add also an icon or an image next to the text that identify the node.
thanks!
版本更新到0.0.12,問題還是沒有解決
@riophae 您好:
我遇到的第一個問題是,單選的下拉選單會出現unknow的預設文字,然後按旁邊的叉叉,才會變成我placeholder預設的文字,我有看您給別人的回答是更新後就可以了,但我的還是在
我遇到的第二個問題是,我用延遲加載後,想要預設default,所以塞值在v-model裡面,用console看,值有進去,可是在網頁上看還是沒有,一訂要點擊下拉選單,才會出現預設的選項,沒辦法直接顯示
以上兩個問題,請您幫忙解答,非常感謝!
vue-treeselect , v-model 相关的问题
希望增加一个功能点
:flat="true"是父节点,子节点都会作为选择项,
希望能增加elementUi的tree那样的功能,只取叶子节点的作为选择项。
Multiple disable branch nodes unselect dont work fine
I have a problem with multiple disable branch nodes.
A three levels tree is not working fine when a item is unselected
https://codepen.io/david-blanco-a/pen/EQXNpL
How to reproduce:
- select 'aba' (click in it)
- select 'aaa' (click in it)
- unselect 'aaa' (click in it)
- select 'aaa' (click in it)
- unselect 'aaa' (click in it)
(You can repite 2 and 3 the times you want) - Show the selected values, there are duplicated! ('aba')
option 不支持扩展属性吗
我的数据格式
[{id:'11',label:'222',children:[],num:''}] 这样的数据格式就会有问题
issue: Changing options via a refresh method
Hi,
Is there a chance of having a refresh method added to the control so that an external component can tell the tree to reload it's options?
Many thanks
Jon
Pug filter options cannot be dynamic
Looks like there is a bug where you are passing an option to markdown-it
- causing the issue mentioned in #28. I'll push up a PR shortly
options are not working with Vuex
Hey Fangzhou,
Struggling with vue-treeselect
to make it working with options from Vuex store that are fetched in created meth. Looks like treeselect is not reactive:
- Tried regular Vuex way
- tried to get data with Promise than resole it in component where
vue-treeselect
is used
Any ideas?
Re-render options after @search-change
On my case, what a I need is to call an Ajax call after the @search-change
redefining the options then. But, it seem that setting the options remotely is not permitted.
<template lang="pug">
treeselect(
v-model="value"
:options="options"
@search-change="searchChange"
)
</template>
<script>
export default {
options: [],
value: null,
methods: {
searchChange () {
this.doAjaxRequest().then((body) => {
this.options = body.data
})
}
}
}
</script>
Doing this way causes the options to be emptied. Am I doing something wrongly or do I have to implement it?
Example:
http://sagalbot.github.io/vue-select/docs/Advanced/Ajax.html
小弟英文不好,有中文文档不,怎么不支持到ie9?
option默认定义好可以,但是动态获取数据再赋值给option,就不显示了
option默认定义好可以,但是动态获取数据再赋值给option,就不显示了
如果source提前定义在data中那没有问题,但是如果我通过接口返回数据格式化后给source重新赋值,树不触发改变
documentation and demo site crashed : (
hi, @riophae thx for the awesome package but as the title suggested, the documentation and demo site crashed : http://vue-treeselect.js.org/
please help us
我应该如何重新渲染Treeselect? (how to rerender the Treeselect)
- template
<treeselectid='xxx' v-if="modalShow">...</treeselect>
<button @click="rerender"></button>
- script
rerender: function(){
this.modalShow = false;
this.modalShow = true;
}
这个方法貌似无效(this method is useless)
或者换而言之,我应该如果在treeSelect的一个生命周期中动态的更改option值, load-root-option只会监听第一次左键点击(in other words, how I can do that I can change the option in dynamic within the
treeselect whole life cycle )
Checkmark off with Bootstrap
First of all thank you for a very nice component!
I'm using it in a Laravel application and everything works nicely, but the checkmark is off by a few pixels (see screenshot).
The issue is with the Bootstrap CSS. See the following pen: https://codepen.io/paulheijman/pen/LOVzjP
Can you please have a look at it?
Also, what is the best way to override the default CSS used by treeselect?
Thanks in advance!
Troubles with custom value change
Hi, first of all - cool plugin, good job. Anyway got some troubles using it: tried to investigate where is a bug. Let me explain: the problem starts when I change the value manually from outside your plugin, I have connected your plugin with vuex store by using props ":value" (v-model is not used here). On change event I commit and change the value in store. This way I make sure that it is connected to store (sort of two way binding). Everything works as expected until I change "valueFormat" to "object", I keep whole object not only ID, also, there are several levels in a tree. When I change the value from outside, I'm making sure that the value passed to vue-treeselect plugin has changed as well, but somehow/somewhere in components inside your plugin doesn't keep up with this change. I guess it isn't capable to detecting changes of reference type objects. I tried copying it totally using method: JSON.parse(JSON.stringify(value)) - doesn't help it.
Made some pics:
https://ibb.co/bWyfXH (Example before)
https://ibb.co/cXqSCH (Example after) - Here: after changing the value visually there are no changes in component
Would be helpful if you could help solving this issue, everything else is working perfectly..:
scrolling IE-11
Hello, guy, i have a small problem:
- i dont scroll in IE 11 on scrollbar click (dropdown closed when i clicking on scrollbar)
Do u fix it ?
作者你好,options是ajax获取的,选项无法显示,该怎么做?
作者你好,options是ajax获取的,选项无法显示,该怎么做?
Consider adding package.lock
Documentation from npm : https://docs.npmjs.com/files/package-lock.json
I wanted to contriboot to this repository. I can't because after a fresh git clone
, npm i
and npm run dev
I get :
~/contriboots/vue-treeselect > npm run dev
> @riophae/[email protected] dev /Users/ireadyouremails/contriboots/vue-treeselect
> node build/dev-server.js
/Users/ireadyouremails/contriboots/vue-treeselect/node_modules/pug-loader/index.js:155
throw e;
^
Error: /Users/ireadyouremails/contriboots/vue-treeselect/docs/partials/guides.pug:37:5
true is not constant. All filters are rendered compile-time so filter options must be constants.
at makeError (/Users/ireadyouremails/contriboots/vue-treeselect/node_modules/pug-error/index.js:32:13)
at /Users/ireadyouremails/contriboots/vue-treeselect/node_modules/pug-filters/lib/handle-filters.js:100:15
at Array.forEach (native)
at getAttributes (/Users/ireadyouremails/contriboots/vue-treeselect/node_modules/pug-filters/lib/handle-filters.js:95:14)
at walk.includeDependencies (/Users/ireadyouremails/contriboots/vue-treeselect/node_modules/pug-filters/lib/handle-filters.js:17:19)
How can I call a function when selecting options?
When I call a function via '@input = "updateValue"', the function is called every time I redraw the vuetreeselect, I need to change the number of elements when selecting option. How can I do it?
tree select disable one node
I want to disable one node whatever level, but there is no way
why "unknown" show?
Configure option key and label
Hi, The document show that option must be use id and label as the key name, can i configure them?
Option to keep placeholder text visible
It'd be great if we could ask Vue-Treeselect to keep the placeholder text visible whenever there is no search text specified by the user.
Use case: when I load the page with some options pre-selected, it's not obvious to the user that they can type to search, or where to do so.
Features request: keyword highlighting & keyboard navigation
Hey again,
It would be nice to have:
- bold matched strings like: search for
enera
make bold that partial in General string - in docs, there is an info about keyboard support but didn't noticed it works
- first
DOWN
arrow press should blur from search input to list - list nav with
UP/DOWN
arrows - node expand/collapse with
LEFT/RIGHT
arrows
- first
Thanks for awesome package 🥇
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.