2016-12-04 34 views
0

您好我正在使用ajax填充分页的数据表,但使用下面的例子来填充输入选择过滤,它只填充下拉列表与当前页面上找到的下拉列表。因此,我从服务器端填充tfoot部分。datatable tfoot输入选择服务器端搜索

https://datatables.net/examples/api/multi_filter_select.html

然而,为了分配上的变化时,我仍然尝试使用下面的方法initComplete ..但它似乎并不像去上更改事件。有没有我做错了..?

  "initComplete": function() { 
      this.api().columns([1]).every(function() { 
       var column = this; 

       console.log(this.value); 
       $('input', this.footer()).on('change', function (e) { 
        column.search(this.value).draw(); 
       }); 
      }); 

服务器端产生的tfoot html代码如下。

<tfoot> 
        <tr> 
         <th> </th> 
         <th> 
          <select class="form-control input-sm"> 
          <option value=""></option><option value="1">a</option> 
          <option value="2">b</option> 
          <option value="3">c</option> 
          <option value="4">d</option> 
          <option value="5">e</option>         
          </select> 
         </th> 
         <th> </th> 
         <th> </th> 
         <th> </th> 
         <th> </th> 
         <th> </th> 
         <th> </th> 
         <th> </th> 
         <th> </th> 
         <th> </th> 
         <th> </th> 
        </tr> 
       </tfoot> 
+0

你问[许多问题(http://stackoverflow.com/users/2274411/superted?tab=问题),你会得到一些很好的答案,但几乎没有接受所有的答案。我回答了你的两个问题,没有任何反馈。合作会增加您获得良好答案的机会。我正在跳过这一个。 –

回答

0

我设法使用下面的代码得到这个工作...

"initComplete": function() { 

      this.api().columns([1]).every(function() { 
       var column = this; 
       console.log($('select', this.footer())); 
       $('select', this.footer()).on('change', function() { 
        alert('reach here'); 
        console.log($(this).val()); 
        var val = $(this).val(); 
        column.search(val ? '^' + val + '$' : '', true, false).draw(); 

       }); 

      });