2015-06-29 28 views
0

我在我的頁面中有一個名爲'search_table'的DataTable。我在表格中有一個額外的標題行,它具有不同的過濾器選項(下拉列表,文本,date_pickers)。對於日期列,我有兩個日期選擇器,一個最小值和一個最大值。我可以根據日期選擇器過濾數據表的數據,但有一個問題:使用DatePicker過濾數據表

當我選擇一個日期時,表中的所有行都消失了,我必須單擊其中一個標題(例如排序數據)來獲取數據。一旦我這樣做,正確的數據顯示(日期在最小和最大之間)。

我用什麼功能來強制數據分析器重新繪製表格?在我準備功能,我有以下代碼:

 $(document).ready(function() { 
     var table = $('#search_table').DataTable(); 
     $(".datepicker").datepicker({ 
      maxDate:0, 
      changeMonth: true, 
      changeYear: true, 
      dateFormat: 'yy-mm-dd', 
      onClose: function(selectedDate) { 
       table.draw();}}); 
     $('#min_create, #max_create, #min_update, #max_update').keyup(function() { table.draw(); }); 
     $('#min_create, #max_create, #min_update, #max_update').click(function() { table.draw(); }); 
     $('#min_create').datepicker().bind('onClose', function(){ table.draw(); }); 
    }); 

min_create,max_create,min_update和max_update是有日期選擇器類的所有投入。 search_table是我的表,它是一個DataTable。

+0

你有沒有嘗試在調用table.draw()方法之前清除數據表? – Sushil

回答

1

我有兩個問題,當修復解決了我的問題。

在我準備功能,我不得不

var table = $('#search_table').DataTable(); 

這應該已經

var table = $('#search_table').dataTable(); 

然後,在代碼的日期選擇器類我有

$(".datepicker").datepicker({ 
     maxDate:0, 
     changeMonth: true, 
     changeYear: true, 
     dateFormat: 'yy-mm-dd', 
     onClose: function(selectedDate) { 
      table.draw();}}); 

,它需要改爲

$(".datepicker").datepicker({ 
     maxDate:0, 
     changeMonth: true, 
     changeYear: true, 
     dateFormat: 'yy-mm-dd', 
     onClose: function(selectedDate) { 
      table.fnDraw();}});