Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove Options from multiselect dropdown in Jquery

I have some table column with some preselected values and now i want to remove those selected values from dropdown(ddlMultiselect) .. Both table column and dropdown option values are same and what i want that those values should be hide/remove from dropdown as per if condition.

$('#sometabletr:gt(0)').each(function () {
            var row = $('td:eq(0) > span', this).text();
            $('#ddlMultiselect :selected').each(function () {
                var col = $(this).val();
                if (row == col) {
                    $(this).remove();
                 }
            });
        });
like image 345
techV Avatar asked Mar 12 '14 08:03

techV


2 Answers

This is the way is do it, fast and easy way

            $('#listname option:selected').each(function (index, option) { 
                $(option).remove(); 
            });      
like image 107
Moe9977 Avatar answered Nov 09 '22 09:11

Moe9977


There is another way to approach this issue.. but setting up classes on the table rows, all you have to do is change the class of the table element itself to hide/show vast amounts of things while only doing a single repaint, which GREATLY improves performance.

In this example, I have the adding of a class hard-coded, but you could use jQuery's addClass and removeClass or look up the best alternatives available.

<doctype html>
<html>
   <header>
      <title>Demo HIde</title>

      <style>
      #mytable.even tr.odd {
        display:none;
      }   
      </style>


   </header>
   <body>


   <table id="mytable">
   <tr class="odd"><td>1</td></tr>
   <tr class="even"><td>2</td></tr>
   <tr class="odd"><td>3</td></tr>
   <tr class="even"><td>4</td></tr>
   <tr class="odd"><td>5</td></tr>
   <tr class="even"><td>6</td></tr>

   </table>

   <script>
   // Show the even values only
   document.getElementById("mytable").className += " even";
   </script>


   </body>
</html>
like image 41
Jeremy J Starcher Avatar answered Nov 09 '22 09:11

Jeremy J Starcher