sc-filtered-list v0.0.1
- FilteredList()
- Installation
- Overview
- Instantiate
- Options
- Defaults
- Events
- Styling
- Templates
- FilteredList.data()
- Add a single object/item
- Get the value
- FilteredList.destroy()
FilteredList()
sc-filtered-list is a UI control to allow the user to quickly choose a
single object from a list of many objects.
To get a reference to the instantiated object use the jQuery data method:
$('#myButton').data('scfilteredlist');Instantiate using code
var filter = new FilteredList(document.querySelector('#myButton'));Options
Give options using the data- attribute.
<button data-sc-filtered-list data-sc-filtered-list-options='{"fuzzy": true}'>The options object must be a properly formatted JSON string.
Give options using code.
var filter = new FilteredList(document.querySelector('#myButton'), {
fuzzy: true
});buttonLabelThe button label (default: "Choose one")fuzzyThe search type. If true "dvd" will match "david" (default: false)itemLabelKeyThe object key to use for the items label (default: "name")listTitleThe title above the list (default: "Select an item")maxNumItemsThe maximum number of items in the list (default: 10)maxNumItemsVisibleThe maximum number of items visible (default: 7)widthThe width of the list (default: 300)sortThe default sort "", "asc", "desc"sortControlVisibleIf the sort control is visible (default: true)
Defaults
To change the defaults, use the global FilteredList variable.
FilteredList.defaults.maxNumItems = 10;Events
The FilteredList uses an event based system with methods on, off and
once.
myList.on('change', function(){});Events
changeWhen the user selects and item and the value has changedcloseWhen the list closesdestroyWhen theFilteredListis destroyedfilteredWhen the search value changesitemFocusWhen an item in the list gains focusopenWhen the list openssortWhen the list is sortedredrawWhen the list redraws itselffetchWhen the list tries to fetch data based on the search term
Styling
CSS is provided and is required however it is plain by design. There are 2 ways to make the list pretty.
- Include bootstrap 3.x
Write your own
Templates
The markup that is generated on instantiation is template driven. These templates can be changed if necessary.
FilteredList.templates.listWrapper
<div class='{{config.className}}-container'>{{!config.templates.listInput}}{{!config.templates.listHeader}}{{!config.templates.listItemWrapper}}</div>FilteredList.templates.listInput
<div class='{{config.className}}-input-container'><input type='text' class='{{config.className}}-input form-control'></div>FilteredList.templates.listHeader
<header class='{{config.className}}-header panel-heading'>{{!config.defaults.listTitle}}{{!config.templates.listSortToggle}}</header>FilteredList.templates.listItemWrapper
<div class='{{config.className}}-items list-group'></div>FilteredList.templates.listItem
<a href class='{{config.className}}-item list-group-item' data-cid='{{cid}}'>{{!key}}</a>FilteredList.templates.listSortToggle
<button type='button' class='{{config.className}}-sort-toggle btn btn-default btn-xs' title='sort'></button>FilteredList.data()
Adds an array of objects/items in bulk
myList.data([{
name: "david"
}, {
name: "max"
}]);Add a single object/item
myList.items.push({
name: "david"
});Get the value
To get the value of the selected object/item use the value property.
myList.value;FilteredList.destroy()
Destroys the FilteredList and invalidates the object.
myList.destroy();Any further calls to methods like
destroyordataetc will return nothing.