bootstrap-checklist is a jquery plug-in which provide a list with checkbox. There are serveral basic settings(e.g color,checkbox style) which you can replaced with your own ones. In the meanwhile, some methods and events (e.g getCheckedData, onCheck) can be accessed for easily use.
- Bootstrap v3.3.6
- jQuery v2.2.1
You can try the bootstrap-checklist on below page. https://jsbin.com/sajezuv/edit?output
the DOM element
<ul id="someId" ></ul>
initialization
$('#someId').checklist({
url:'/somepath/test.json'
});
var testData = [
{
id:'id_1',
name:'leon',
checked:false,
selected:true
},
{
id:'id_2',
name:'bruce',
checked:true,
selected:false
}
]
- each object in the Array is a li(DOM Element)'s data.
- the data(id,name,checked,selected) were stored in li(DOM Element) by jquery method data(),so you cant find the data in DOM structure, but you can retrieve it via data() method.
$('#someId').checklist({
url:'/somePath/someMethod.do',
multiselect:false,
settings:{
color:'red',
backgroud_color:'#1234FF'
}
});
Array. A javascript array containing the data to be displayed.
String. Checklist will use this url to retrieve the Data with jquery.ajax method. Be noticed that the url param will be ignored when the data param was given.
Boolean(Default false). Whether or not allow to select mutiple rows.
Boolean(Default true). Just as what its name is.
Boolean(Default true). if it is setted to be true, checkbox will be checked when you select a row. No matter how you select a row, either click the row or use Checklist's setSelect method.
Object. Be noticed this is a javascript Object, not a string. It contains 4 variables.
- color:String. Font color for those li element been selected. Hexadecimal value or color value are accepted, e.g.'#FFFFFF' or 'red'. (Default '#FFFFFF')
- backgroud_color:String. Li element backgroud-color when they are selected. Hexadecimal value or color value are accepted, e.g.'#FFFFFF' or 'red'. (Default '#428BCA')
- on. String(Default 'glyphicon glyphicon-check'), checked box icon.
- off. String(Default 'glyphicon glyphicon-unchecked'), uncheck box icon.
Example
1,
var result = $('#someId').checklist('getCheckedData');
2,
$('#someId').checklist('methodName',parameter);
Checks a specific li element by its id.
- id. String, it's li's id.
- silent. Boolean, determine whether or not relative Event onCheck will be triggerd. Leaving it blank, the event will not be triggerd.
Unchecks a specific li element by its id.
- parameter is the same as setCheck.
Selects a specific li element by its id.
- parameter is the same as setCheck.
Unselects a specific li element by its id.
- parameter is the same as setCheck.
Unselects all li element.
Unchecks all li element.
Returns a Array containing the checked li element data, each data is a javascript object.
Example
$('#someId').checklist({
onSelect:function(event,li){
//callback function body
}
});
following events will be triggered when corresponding behavior occurred. Meanwhile, they can be triggered via each relative method on conditions that the method's silent param was setted to be true.
parameters:
- event, event object.
- li, the li DOM element.