HemantNegi / jquery.sumoselect

A jQuery Single/Multi Select plugin which can be used on almost any device
http://hemantnegi.github.io/jquery.sumoselect
560 stars 287 forks source link
customizable jquery jquery-plugin responsive select

jquery.sumoselect

jquery.sumoselect.js - A beautiful cross device Single/Multi Select jQuery Select plugin.

A jQuery plugin that progressively enhances an HTML Select Box into a Single/Multiple option dropdown list. The dropdown list can be fully customizable using simple css. It can adapt itself according to any device, keeping in mind that the User Experience is not broken.

View Live Demo Here

Documentaion Documentation Here

Latest stable : Download from here

CDNJS

The folks at CDNJS host a copy of the library. The CDN is updated after the release is made public, which means there is a delay between the publishing of a release and its availability on the CDN, so keep that in mind. Just use these links:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.sumoselect/3.1.6/sumoselect.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.sumoselect/3.1.6/jquery.sumoselect.min.js"></script>

Notable Features

Requirements

jQuery 1.8.3+ (It is always recommended to use the latest version of jQuery)

Desktop Browser Support

IE8+, Firefox 4+, Chrome, Safari 4+, Opera 11+ (Other browsers may work, but I did not test on them)

Mobile/Tablet Browser Support

iOs 3+, Android 2.1+ , Windows Mobile (Other browsers may work, but I did not test on them)

Forking

If you find that you need a feature that SumoSelect does not currently support, either let me know via the SumoSelect issue tracker, or fork SumoSelect on Github and easily extend SumoSelect to create your own widget!

Usage

To just go with the default options simply do

$(document).ready(function () {
  $('.selectBox').SumoSelect();
});

To provide optional settings, simply pass a settings object to SumoSelect()

$(document).ready(function () {
  $('.selectBox').SumoSelect({
    placeholder: 'This is a placeholder',
    csvDispCount: 3
  });
});

You can also use data attributes to set options

<select class="selectBox" multiple data-max="2">

If you want an instance to the SumoSelect object to call handler methods

const select;
$(document).ready(function () {
  select = $('.selectBox').SumoSelect();
});

NOTE: SumoSelect returns an array of select elements if there are more than one in the matching selector.

You can also find the instance to the SumoSelect object by directly selecting your select element like

$('select.selectBox')[0].sumo. .....

You can perform all the operations on the underlying original select and then reload the UI by

$('select.selectBox')[0].sumo.reload();
You can bind your handlers to some sumoselect specific events eg.
$('select.selectBox').on('sumo:opened', function(sumo) {
  // Do stuff here
  console.log("Drop down opened", sumo)
});

Available events

Settings

Below are the available settings:

The default settings are :

{
    placeholder: 'Select Here',
    csvDispCount: 3,
    captionFormat:'{0} Selected', 
    captionFormatAllSelected:'{0} all selected!',
    floatWidth: 400,
    forceCustomRendering: false,
    nativeOnDevice: ['Android', 'BlackBerry', 'iPhone', 'iPad', 'iPod', 'Opera Mini', 'IEMobile', 'Silk'],
    outputAsCSV: false,
    csvSepChar: ',',
    okCancelInMulti: false,
    isClickAwayOk: false,
    triggerChangeCombined: true,
    selectAll: false,
    search: false,
    searchText: 'Search...',
    searchFn: function (haystack, needle, el) {
      return haystack.toLowerCase().indexOf(needle.toLowerCase()) < 0;
    },
    noMatch: 'No matches for "{0}"',
    prefix: '',
    locale: ['OK', 'Cancel', 'Select All'],
    up: false,
    showTitle: true,
    max: null,
    renderLi: (li, originalOption) => li,
    clearAll: false,
    closeAfterClearAll: false
}

Furthur Documentation

License

Copyright (c) 2016 Hemant Negi Licensed under the MIT license.