2014-09-01 39 views
0

我使用dataTables來顯示從服務器呈現的數據。dataTable列搜索給出未定義的錯誤

var dtable = $("#oolt_control_body").find("#product-list").dataTable({ 
    "sPaginationType": "full_numbers", 
    "iDisplayLength": 25, 
    "aoColumnDefs": [ 
     { "bSortable": false, "aTargets": [ 0 ] } 
    ] 
}); 

$("#product-list tfoot th").each(function (i) { 
     var select = $('<select><option value=""></option></select>') 
      .appendTo($(this).empty()) 
      .on('change', function() { 
       var val = $(this).val(); 

       dtable.column(i) //returns undefined 
        .search(val ? '^'+$(this).val()+'$' : val, true, false) 
        .draw(); 
      }); 

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

代碼的後半部分取自dataTables website。我使用1.9.4版,但是使用1.10.2進行測試,但徒勞無益。有人可以建議可能是什麼問題?

回答

0

您是否嘗試切換到.DataTable(注意大寫「D」)?

總之,.dataTable仍然有效,但會返回與.DataTable不同類型的對象。

http://datatables.net/faqs/#api

+0

我選擇了做它用不同的方式,所以我不能測試你的解決方案,但可能對別人有用。 – sri 2014-09-29 15:06:41