2011-07-12 120 views
6

我在使用DataTables和pipelining。除非我嘗試輸入額外的列來保存「編輯」鏈接,否則我工作得很好。見表this表。DataTables,Ajax流水線

這裏是server_processing.php的顯示列的片段:

/* Array of database columns which should be read and sent back to DataTables. 
    * Use a space where you want to insert a 
    * non-database field (for example a counter or static image) 
    */ 
    $aColumns = array('user','email',); 

這裏是客戶方:

$(document).ready(function(){ 
     $('#example').dataTable({ 
      "bProcessing": true, 
      "bServerSide": true, 
      "sAjaxSource": "scripts/server_processing.php", 
      "fnServerData": fnDataTablesPipeline, 
      aoColumns: [null, null, {"bSortable": false}] 
    }).makeEditable({ 
     sUpdateURL: "UpdateData.php", 
     sAddURL: "AddData.php", 
     sAddHttpMethod: "POST", 
     sDeleteURL: "DeleteData.php", 
     sDeleteHttpMethod: "POST", 
     aoColumns: [ { } , { } , null ] 
    }); 
    }); 

那麼,爲什麼不是這方面的工作?

+1

我與數據表的經驗不包括使用流水線,但添加了「虛擬列時「 - 例如,編輯列,複選框,計算行,通常您需要在」aoColumns「數組中添加一個佔位符。所以我會將'aoColumns:[null,null,{「bSortable」:false}] aoColumns:[null,null,{「bSortable」:false}]更改爲'aoColumns:[null,null,null,{「bSortable 「:false}]' – artlung

+2

另外,寫數據表的人(Alan Jardine,我認爲?)在幫助你時有很大的幫助,如果你有任何問題的話。他很聰明,顯然沒有人知道這個插件比創作者本身更好! – martincarlin87

回答

3

我自己做了完全相同的事情。我喜歡使用aoColumnDefs配置我的所有列,因爲您可以一次添加多個列的配置選項。

// Disable sorting on the 3rd column 
'aoColumnDefs': [{'aTargets': [2], 'bSortable': false}] 

注意aTargets是要應用這些設置,列索引的數組。因此,如果要添加更多鏈接列(例如,刪除鏈接),則可以關閉對這些列的排序,而不必每次都重寫列定義。

// Disable sorting on the 3rd and 4th column 
'aoColumnDefs': [{'aTargets': [2,3], 'bSortable': false}] 

而且,正如我說的,你可以在這同一陣列添加更多配置選項列:

// Disable sorting on the 3rd and 4th column and sort 1st column by string 
'aoColumnDefs': [ 
    {'aTargets': [2,3], 'bSortable': false} 
    {'aTargets': [0], 'sType': 'string'} 
]