javascript - Search Not Working In Dynamic Bootstrap Multiselect -
i'm using http://davidstutz.github.io/bootstrap-multiselect/ creating bootstrap multiselect controls in webpage.
the below fiddle link static data want achieve using dynamic data:
https://jsfiddle.net/drocks/mrmlrsad/4/
//please refer fiddle
the search option works fine in case values of select box static, if dynamically created, multiselect gets created. search filter not working in case. code similar fiddle below, difference being search filter part doesn't work in actual code, works in fiddle.
fiddle link dynamic data. https://jsfiddle.net/drocks/mrmlrsad/5/
//please refer fiddle
this code. html code
<select id="lstfieldlist" ></select>
jquery code [updated]:
function uncheckfields(field_id) { $('#' + field_id).multiselect('deselectall', true); } //json_obj value fiddle. createmultiselectbox(json_obj); //this function creates multiselect function createmultiselectbox(json_obj) { var element_string = ""; var default_ele_set = 0; var def_element_first = "1"; //if first y flag should considered var def_element_last = "n"; //if last y flag should considered var def_element = def_element_first; //change value here toggle between default selection var tmp = []; (var key in json_obj) { var val = json_obj[key]; //alert("key: " + key); var chk_box_ctr = 0; var element; for(var child_key in val) { //alert("key: " + child_key + "\nvalue: " + val[child_key]); var default_value = child_key.split(",")[7]; //alert("default_value: " + default_value); if(!chk_box_ctr) { g_max_pagesize = child_key.split(",")[8]; //alert("g_max_pagesize: " + g_max_pagesize); } if(def_element == def_element_first) { if(default_value == "y" && !default_ele_set) { //element_string += '<option value="' + child_key + '" selected="selected">' + val[child_key] + '</option>'; element = {"label": val[child_key],"value":child_key}; } else { //element_string += '<option value="' + child_key + '">' + val[child_key] + '</option>'; element = {"label": val[child_key],"value":child_key}; } } else { if(default_value == "y") { //element_string += '<option value="' + child_key + '" selected="selected">' + val[child_key] + '</option>'; element = {"label": val[child_key],"value":child_key}; } else { //element_string += '<option value="' + child_key + '">' + val[child_key] + '</option>'; element = {"label": val[child_key],"value":child_key}; } } tmp.push(element); } if(def_element == def_element_last) { uncheckfields('lstfieldlist'); } } //$('#lstfieldlist').append(element_string); //$('#lstfieldlist').multiselect('rebuild'); $("#lstfieldlist").multiselect('dataprovider', tmp); $('#lstfieldlist').multiselect({ maxheight: 200, buttonwidth:"100%", enablefiltering:true, enablecaseinsensitivefiltering:true, /*maxheight: 200, enablecaseinsensitivefiltering: true, //enablefiltering: true, onchange: function(option, checked, select) { alert('changed option ' + $(option).val() + '.' + "\nchecked: " + checked + "\nselect: " + select); if(checked) { //uncheckfields('lstfieldlist'); } else { uncheckfields('lstfieldlist'); } }*/ }); var elem = $('#lstfieldlist').next(); elem.attr('class',(elem.attr('class') + ' open')); }
what problem? because same code present in both files.
any appreciated.
thanks in advance.
create array var tmp = [];
create json while looping option
element = {"label": this.name,"value":this.id};
and push each element tmp
tmp.push(element);
and pass tmp
array multi select
$("#lstfieldlist").multiselect('dataprovider', tmp);
and add multiselect dropdown by
$("#lstfieldlist").multiselect({ maxheight: 260, buttonwidth:"100%", enablefiltering:true, enablecaseinsensitivefiltering:true, });
Comments
Post a Comment