Socket
Socket
Sign inDemoInstall

tree-multiselect

Package Overview
Dependencies
0
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tree-multiselect

jQuery multiple select with nested options


Version published
Weekly downloads
616
decreased by-20.1%
Maintainers
1
Install size
527 kB
Created
Weekly downloads
 

Readme

Source

jQuery Tree Multiselect

Build Status Coverage Status devDependency Status

This plugin allows you to add a sweet treeview frontend to a select element. The underlying select element can be used as it was before.

  • Requires jQuery v1.8+

Demo

My website has a simple demo running.

Usage

Make sure your select has the multiple attribute set. Also, make sure you've got <meta charset="UTF-8"> or some of the symbols may look strange.

Options on your select
Option Attribute nameDescription
selectedHave the option pre-selected. This is actually part of the HTML spec. For specified ordering of these, use data-index
readonlyUser cannot modify the value of the option. Option can be selected (ex. <option selected readonly ...)
data-sectionThe section the option will be in; can be nested
data-descriptionA description of the attribute; will be shown on the multiselect
data-indexFor pre-selected options, display options in this order, lowest index first. Repeated items with the same index will be shown before items with a higher index. Otherwise items will be displayed in the order of the original select

All of the above are optional.

Your data-section can have multiple section names, separated by the sectionDelimiter option.

Ex. data-section="top/middle/inner" will show up as

  • top
    • middle
      • inner
        • your option
The JavaScript
$("select").treeMultiselect();

And now with some params.

$("select").treeMultiselect({searchable: true});
function treeOnChange(allSelectedItems, addedItems, removedItems) {
  console.log("something changed!");
}

$("select").treeMultiselect({
  allowBatchSelection: false,
  onChange: treeOnChange,
  startCollapsed: true
});

The function returns returns an array of objects, each of which contains two functions, remove and reload. remove removes the tree, and reload reinitializes the tree from its select element. User-changed options will be lost!

var trees = $("select").treeMultiselect();
var firstTree = trees[0];

// remove the tree
firstTree.remove();

// or, change the select element with new options, then...
firstTree.reload();
Params
NameDefaultDescription
allowBatchSelectiontrueSections have checkboxes which when checked, check everything within them
collapsibletrueAdds collapsibility to sections
enableSelectAllfalseEnables selection of all or no options
selectAllTextSelect AllOnly used if enableSelectAll is active
unselectAllTextUnselect AllOnly used if enableSelectAll is active
freezefalseDisables selection/deselection of options; aka display-only
hideSidePanelfalseHide the right panel showing all the selected items
onChangenullCallback for when select is changed. Called with (allSelectedItems, addedItems, removedItems), each of which is an array of objects with the properties text, value, initialIndex, and section
onlyBatchSelectionfalseOnly sections can be checked, not individual items
sortablefalseSelected options can be sorted by dragging (requires jQuery UI)
searchablefalseAllows searching of options
searchParams['value', 'text', 'description', 'section']Set items to be searched. Array must contain 'value', 'text', or 'description', and/or 'section'
sectionDelimiter/Separator between sections in the select option data-section attribute
showSectionOnSelectedtrueShow section name on the selected items
startCollapsedfalseActivated only if collapsible is true; sections are collapsed initially

Installation

Load jquery.tree-multiselect.min.js on to your web page. The css file is optional (but recommended).

You can also use bower - bower install tree-multiselect

FAQ

Help! The first element is selected when I create the tree. How do I make the first element not selected? You didn't set the multiple attribute on your select. This is a property of single-option select nodes - the first option is selected.

License

MIT licensed.

Keywords

FAQs

Last updated on 02 Nov 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc