javascript - Can't define options on bootstrap multiselect inputs when using 'dataprovider' method to generate list items -


i'm using bootstrap-multiselect extension create drop down menus allow multiple selection, have search feature, , have 'select all' option. pretty easy:

$('#my-selector').multiselect({     enablefiltering: true,     includeselectalloption: true, }); 

now want generate these dropdowns programmatically (from ajax response): so, documentation recommends using 'dataprovider' method. can't figure out how accomplish while preserving enablefiltering , includeselectalloption options.

my intuition should doing this:

$('#example-dataprovider').multiselect({     enablefiltering: true,     includeselectalloption: true });    var options = [   {label: 'option 1', title: 'option 1', value: '1'},   {label: 'option 2', title: 'option 2', value: '2'},   {label: 'option 3', title: 'option 3', value: '3'},   {label: 'option 4', title: 'option 4', value: '4'},   {label: 'option 5', title: 'option 5', value: '5'},   {label: 'option 6', title: 'option 6', value: '6'} ];  $('#example-dataprovider').multiselect('dataprovider', options); 

but doesn't work. can data-provider method work if invokes simpler multiselect call construct form:

$('#example-dataprovider').multiselect(); 

but can't figure out how add filtering , selectall after fact.

how specify filtering , selectall options on dropdown construct programmatically?

here's fiddle.

found workaround. feel isn't how i'm "supposed" using tool, seems work. i'd still interested learn why dataprovider method doesn't appear working way expected to.

anyway, current solution use d3 replace <option> elements whatever want, , call multiselect 'rebuild' method reconstruct widget.

$(document).ready(function() {     $('#example-filterbehavior').multiselect({         enablefiltering: true,         includeselectalloption: true,         selectallvalue: 'select-all-value',         selectallname: 'select-all-name',         filterbehavior: 'value',         selectedclass: 'multiselect-selected'     }); });   var options = [{'value':1, 'title':'first'},                {'value':2, 'title':'second'}];  form = d3.selectall('#example-filterbehavior');  form.selectall('option').remove();  form.selectall('option')     .data(options)     .enter().append('option')     .attr('value', function(d){return d.value})     .text(function(d){return d.title});   $('#example-filterbehavior').multiselect('rebuild'); 

jsfiddle posterity.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -