2016-12-29 11 views
0

这里是我的代码:数据表添加了选择的形式

的Javascript:

$(document).ready(function() { 
    $('#example').DataTable({ 
     "ajax": '../ajax/data/arrays.txt' 
    }); 
}); 

HTML

<select id="office-select" name="idOffice"> 
    <option value="">All</option> 
    <option value="1">Berlin</option> 
    <option value="2">New York</option> 
    <option value="3">Tokio</option> 
</select> 
<table id="example" class="display" width="100%" cellspacing="0"> 
     <thead> 
      <tr> 
       <th>Name</th> 
       <th>Position</th> 
       <th>Office</th> 
       <th>Extn.</th> 
       <th>Start date</th> 
       <th>Salary</th> 
      </tr> 
     </thead> 
     <tfoot> 
      <tr> 
       <th>Name</th> 
       <th>Position</th> 
       <th>Office</th> 
       <th>Extn.</th> 
       <th>Start date</th> 
       <th>Salary</th> 
      </tr> 
     </tfoot> 
    </table> 

我选择从中选择形式办事处(例如纽约),我想从文件'../ajax/data/arrays.txt?idOffice=2'动态地重新加载表格的内容'

怎样才能我这么做?非常感谢你:)

回答

0

使用下面的代码:

$('#office-select').on('change', function(){ 
    $('#example').DataTable().column(2).search($(this).val()).draw(); 
}); 

this example代码和演示。