Advertisement
rikisaraan

select2 example

Sep 9th, 2020
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.77 KB | None | 0 0
  1. <div class="card">
  2.     <div class="header bg-orange">
  3.         <h2>Form Kelola Data Daftar Belanja</h2>
  4.     </div>
  5.     <div class="body">
  6.         <div class="table-responsive">
  7.             <a id="addCart" href="javascript:void(0);" class="btn btn-lg bg-black waves-effect waves-light">Tambah Produk</a>
  8.             <hr>
  9.             <table style="width:100%" id="tableAjaxcategory" class="table table-bordered">
  10.                 <thead>
  11.                     <tr>
  12.                         <th width="50%">Produk</th>
  13.                         <th>Jumlah Pembelian</th>
  14.                         <th>Satuan</th>
  15.                         <th colspan="2">Harga Beli</th>
  16.                     </tr>
  17.                 </thead>
  18.                 <tbody id="listCart"></tbody>
  19.             </table>
  20.         </div>
  21.     </div>
  22. </div>
  23.  
  24. <script>
  25.     let id = 0;
  26.     $(document).ready(function() {
  27.         if (id < 1) $("#addCart").trigger("click");
  28.    });
  29.  
  30.    $(document).on("click", "#addCart", function(e) {
  31.        e.preventDefault();
  32.        addCart();
  33.    });
  34.  
  35.    $(document).on("click", ".delete", function(e) {
  36.        e.preventDefault();
  37.        $(this).parent().parent().remove();
  38.    });
  39.  
  40.    function initliaizeSelec2() {
  41.        $('.multiSelect' + id).select2({
  42.            width: 'resolve',
  43.            theme: "classic"
  44.        });
  45.    }
  46.  
  47.    function addCart() {
  48.        let rowProduct = `
  49.            <tr style="background-color:#FAFBFC;">
  50.                 <td>
  51.                     <select style="width:100%" name="inventory_id" class="multiSelect` + id + ` form-control" required>
  52.                         <option value="">Silahkan Pilih Produk</option>
  53.                         <?php
  54.                        foreach ($dataProduct as $product) {
  55.                            echo "<option value='" . $product->inventory_id . "'>" . $product->product_name . " - " . $product->brand_name . "</option>";
  56.                         }
  57.                         ?>
  58.                     </select>
  59.                 </td>
  60.                 <td>
  61.                     <input type="text" id="transaction_detail_request_qty" name="transaction_detail_request_qty" class="form-control" required>
  62.                 </td>
  63.                 <td>kg</td>
  64.                 <td>
  65.                     <input type="text" id="transaction_detail_new_price" name="transaction_detail_new_price" class="form-control" required>
  66.                 </td>
  67.                 <td>
  68.                     <a href="javascript:void(0);" class="delete pull-right btn bg-red waves-effect">
  69.                         <i class="material-icons">delete</i>
  70.                     </a>
  71.                 </td>
  72.             </tr>
  73.         `;
  74.  
  75.         $("#listCart").append(rowProduct);
  76.  
  77.         initliaizeSelec2();
  78.  
  79.         id++;
  80.     }
  81. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement