Giter Site home page Giter Site logo

nsmcan / tree-multiselect.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from patosai/tree-multiselect.js

0.0 1.0 0.0 661 KB

jQuery multiple select with nested options

Home Page: https://www.patosai.com/projects/tree-multiselect

License: MIT License

JavaScript 91.96% Shell 0.29% CSS 2.97% HTML 4.78%

tree-multiselect.js's Introduction

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+
  • Does not work on IE8. Pull requests welcome!

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 name Description
selected Have the option pre-selected. This is actually part of the HTML spec
readonly User cannot modify the value of the option. Option can be selected (ex. <option selected readonly ...)
data-section The section the option will be in; can be nested
data-description A description of the attribute; will be shown on the multiselect
data-index For pre-selected options, display options in this order, lowest index first. Conflicts will be overwritten by the last item with the same data-index

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
Name Default Description
allowBatchSelection true Sections have checkboxes which when checked, check everything within them
collapsible true Adds collapsibility to sections
enableSelectAll false Enables selection of all or no options
selectAllText Select All Only used if enableSelectAll is active
unselectAllText Unselect All Only used if enableSelectAll is active
freeze false Disables selection/deselection of options; aka display-only
hideSidePanel false Hide the right panel showing all the selected items
onChange null Callback 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
onlyBatchSelection false Only sections can be checked, not individual items
sortable false Selected options can be sorted by dragging (requires jQuery UI)
searchable false Allows 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
showSectionOnSelected true Show section name on the selected items
startCollapsed false Activated 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.

tree-multiselect.js's People

Contributors

patosai avatar axpauls avatar wilsonge avatar nsmcan avatar

Watchers

 avatar

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.