简体   繁体   中英

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

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>

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

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();

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...'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM