How to reset the select box values in Jquery sumoselect Multi select plugin

社会主义新天地 提交于 2019-12-23 02:43:18

问题


I am using Jquery sumoselect plugin for multiselection option. I want to reset the values on click of some button.

Here is my code:

<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="js/jquery.sumoselect.min.js"></script>
<link href="css/sumoselect.css" rel="stylesheet" />

<script type="text/javascript">
    $(document).ready(function () {
        window.asd = $('.SlectBox').SumoSelect({  okCancelInMulti: true });

    });

Here is the function for reset of multiselect content

function clearContents()
    {
         $('select.SlectBox')[0].sumo.unload();
    }

<select name="is_dist_handled"  multiple="multiple" placeholder="Select"  class="SlectBox">
    <option value="Y">Yes</option>
    <option value="N">No</option>
</select>

回答1:


You can use the sumo.unSelectItem();. Source here

$(document).ready(function () {
   $('.SlectBox').SumoSelect({  okCancelInMulti: true });

   $('button').on('click', function(){
     var num = $('option').length;
     for(var i=0; i<num; i++){
       $('.SlectBox')[0].sumo.unSelectItem(i);
     }
   });

});

Fiddle

Update

To remove only the selected options

$('button').on('click', function () {
    var obj = [];
    $('option:selected').each(function () {
        obj.push($(this).index());
    });

    for (var i = 0; i < obj.length; i++) {
        $('.SlectBox')[0].sumo.unSelectItem(obj[i]);
    }
});

Fiddle




回答2:


This is working fine for me.

('#Multi_Lead_Status')[0].sumo.unload();
$('#Multi_Lead_Status').val('');
$('#Multi_Lead_Status').SumoSelect({
   search: true,
   placeholder: 'Status',
   csvDispCount: 2,
   searchText: 'Search...'
});



回答3:


This would be the possible option to unSelect all the selection:

.unSelectAll()

Un selects all items in the list

//Un select all items

$('select.SlectBox')[0].sumo.unSelectAll();



来源:https://stackoverflow.com/questions/27722149/how-to-reset-the-select-box-values-in-jquery-sumoselect-multi-select-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!