2016-12-19 16 views
0

深層フィルタ機能のためにテーブルの下に選択範囲を追加しようとしていますが、次のコードを追加しましたが、データテーブルがエラーを再初期化できません。データテーブルデータテーブルを再初期化できません

コードソース:https://datatables.net/examples/api/multi_filter_select.html

これは、追加したコードです:

$(document).ready(function() { 
    $('#price-increase-table').DataTable({ 
      initComplete: function() { 
        this.api().columns().every(function() { 
         var column = this; 
         var select = $('<select><option value=""></option></select>') 
          .appendTo($(column.footer()).empty()) 
          .on('change', function() { 
           var val = $.fn.dataTable.util.escapeRegex(
            $(this).val() 
           ); 

           column 
            .search(val ? '^'+val+'$' : '', true, false) 
            .draw(); 
          }); 

        column.data().unique().sort().each(function (d, j) { 
         select.append('<option value="'+d+'">'+d+'</option>') 
       }); 
      }); 
     } 
    }); 
}); 

そして、この私のscript.jsファイル内のコード:

$(document).ready(function() { 
    var table = $('#price-increase-table').DataTable({ 
     //"scrollY": "500px", 
     "paging": true, 
     dom: 'Bfrtip', 
     // Configure the drop down options. 
     lengthMenu: [ 
      [ 10, 25, 50, -1 ], 
      [ '10 rows', '25 rows', '50 rows', 'Show all' ] 
     ], 
     // Add to buttons the pageLength option. 
     buttons: [ 
      'pageLength','excel','print' 
     ] 
    }); 

    $('a.toggle-vis').on('click', function (e) { 
     e.preventDefault(); 

     // Get the column API object 
     var column = table.column($(this).attr('data-column')); 

     // Toggle the visibility 
     column.visible(! column.visible()); 
    }); 

    $("#price-increase-table").width("100%"); 
}); 

があることには、この必要性をい1つの関数に統合されましたか?もしそうなら、私はあまりにもエラーで実行し続ける。

EDIT:表のための

HTML:

<table id="price-increase-table" class="display table table-striped table-bordered dt-responsive"> 
<thead> 
    <tr> 
     <th>SKU</th> 
     <th>Item Name</th> 
     <th>Supplier</th> 
     <th>Current Net</th> 
     <th>Current Matrix</th> 
     <th>Current Band A</th> 
     <th>Customer Increase</th> 
     <th>New Invoice</th> 
     <th>New Net</th> 
     <th>New Matrix</th> 
     <th>New Band A</th> 
     <th>Increased Date</th> 
    </tr> 
</thead> 
<tbody> 
<?php while($res = sqlsrv_fetch_array($def, SQLSRV_FETCH_ASSOC)) : ?> 
    <tr> 
     <td class="price-end"><?php echo $res['ItemCode'];?> 
      <input type="hidden" name="curItemCode[]" value="<?php echo $res['ItemCode']; ?>" /> 
     </td> 

     <td><?php echo $res['ItemName'];?></td> 
     <td><?php echo $res['BrandOwner'];?></td> 
     <td><?php echo $res['CurrentNet'];?></td> 
     <td><?php echo $res['CurrentMX'];?></td> 
     <td><?php echo $res['CurrentBandA'];?></td> 
     <td> 
      <input type="text" name="CustomerIncrease[]" class="form-control" value="<?php if(!empty($res['CustomerIncrease'])){echo $res['CustomerIncrease'];}?>" /> 
     </td> 
     <td> 
      <input type="text" name="NewInvoice[]" class="form-control" value="<?php if(!empty($res['NewInvoice'])){echo $res['NewInvoice'];}?>" /> 
     </td> 
     <td> 
      <input type="text" name="NewNet[]" class="form-control" value="<?php if(!empty($res['NewNet'])){echo $res['NewNet'];}?>" /> 
     </td> 
     <td> 
      <input type="text" name="NewMX[]" class="form-control" value="<?php if(!empty($res['NewMX'])){echo $res['NewMX'];}?>" /> 
     </td> 
     <td> 
      <input type="text" name="NewBandA[]" class="form-control" value="<?php if(!empty($res['NewBandA'])){echo $res['NewBandA'];}?>" /> 
     </td> 
     <td> 
      <input type="text" name="IncreaseDate[]" class="form-control col-md-7 col-xs-12" value="<?php if(!empty($res['IncreaseDate'])){echo $res['IncreaseDate'];}?>" /> 
     </td> 
    </tr> 
<?php endwhile; ?> 
</tbody> 

+0

そんなに – Deep

+0

を追加しましたHTMLを示し、これは私がまさに必要です! – PHPNewbie

答えて

1

あなたがHTMLでを追加する必要があり、あなたが再初期化データテーブルの問題を取得する他のスクリプトをマージする必要があります。

$(document).ready(function() { 
 
    var table = $('#price-increase-table').DataTable({ 
 
     
 
     initComplete: function() { 
 
      this.api().columns().every(function() { 
 
       var column = this; 
 
       var select = $('<select><option value=""></option></select>') 
 
        .appendTo($(column.footer()).empty()) 
 
        .on('change', function() { 
 
         var val = $.fn.dataTable.util.escapeRegex(
 
          $(this).val() 
 
         ); 
 
    
 
         column 
 
          .search(val ? '^'+val+'$' : '', true, false) 
 
          .draw(); 
 
        }); 
 
    
 
       column.data().unique().sort().each(function (d, j) { 
 
        select.append('<option value="'+d+'">'+d+'</option>') 
 
       }); 
 
      }); 
 
     }, 
 
     "paging": true, 
 
     dom: 'Bfrtip', 
 
     // Configure the drop down options. 
 
     lengthMenu: [ 
 
      [ 10, 25, 50, -1 ], 
 
      [ '10 rows', '25 rows', '50 rows', 'Show all' ] 
 
     ], 
 
     // Add to buttons the pageLength option. 
 
     buttons: [ 
 
      'pageLength','excel','print' 
 
     ] 
 
    }); 
 

 
    $('a.toggle-vis').on('click', function (e) { 
 
     e.preventDefault(); 
 

 
     // Get the column API object 
 
     var column = table.column($(this).attr('data-column')); 
 

 
     // Toggle the visibility 
 
     column.visible(! column.visible()); 
 
    }); 
 

 
    $("#price-increase-table").width("100%"); 
 
});
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
 
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script> 
 

 
<table id="price-increase-table" class="display" cellspacing="0" width="100%"> 
 
     <thead> 
 
    <tr> 
 
     <th>SKU</th> 
 
     <th>Item Name</th> 
 
     <th>Supplier</th> 
 
     <th>Current Net</th> 
 
     <th>Current Matrix</th> 
 
     <th>Current Band A</th> 
 
     <th>Customer Increase</th> 
 
     <th>New Invoice</th> 
 
     <th>New Net</th> 
 
     <th>New Matrix</th> 
 
     <th>New Band A</th> 
 
     <th>Increased Date</th> 
 
    </tr> 
 
</thead> 
 
    <tfoot> 
 
    <tr> 
 
     <th>SKU</th> 
 
     <th>Item Name</th> 
 
     <th>Supplier</th> 
 
     <th>Current Net</th> 
 
     <th>Current Matrix</th> 
 
     <th>Current Band A</th> 
 
     <th>Customer Increase</th> 
 
     <th>New Invoice</th> 
 
     <th>New Net</th> 
 
     <th>New Matrix</th> 
 
     <th>New Band A</th> 
 
     <th>Increased Date</th> 
 
    </tr> 
 
</tfoot> 
 
     <tbody> 
 
      <tr> 
 
       <td>123</td> 
 
       <td>System</td> 
 
       <td>ABC</td> 
 
       <td>61</td> 
 
       <td>2011</td> 
 
       <td>D</td> 
 
       <td>2</td> 
 
       <td>yes</td> 
 
       <td>67</td> 
 
       <td>K</td> 
 
       <td>L</td> 
 
       <td>2016/12/19</td> 
 
      </tr> 
 
      <tr> 
 
       <td>124</td> 
 
       <td>System</td> 
 
       <td>ABC</td> 
 
       <td>61</td> 
 
       <td>2011</td> 
 
       <td>D</td> 
 
       <td>2</td> 
 
       <td>yes</td> 
 
       <td>67</td> 
 
       <td>K</td> 
 
       <td>L</td> 
 
       <td>2016/12/19</td> 
 
      </tr> 
 
      <tr> 
 
       <td>125</td> 
 
       <td>System</td> 
 
       <td>ABC</td> 
 
       <td>61</td> 
 
       <td>2011</td> 
 
       <td>D</td> 
 
       <td>2</td> 
 
       <td>yes</td> 
 
       <td>67</td> 
 
       <td>K</td> 
 
       <td>L</td> 
 
       <td>2016/12/19</td> 
 
      </tr> 
 
      
 
     </tbody> 
 
    </table>

+0

感謝を編集するために私達にあなたのテーブルのためのhtml – PHPNewbie

+0

あなたは歓迎です:) – Deep

関連する問題