效果以下:html
使用createdCell函數進行單元格合併,具體參考:www.datatables.club/reference/o…bash
"columnDefs":[{
"targets": 0,
"orderable" : false,
"data":null,
"createdCell": function(td, cellData, rowData, row, col) {
if(rowData.columnNum > 1){
$(td).remove();
}
if(rowData.columnNum == 1){
$(td).attr("rowspan", rowData.columnCount);
}
}
}]
複製代碼
rowData爲每一行的數據內容,判斷當前行在分組內的columnNum,等於1的添加屬性rowspan,並設置其值爲columnCount;大於1的將td單元格刪除。 PS:在使用createdCell函數時老是報錯以下:函數
Add: data: null to your first column to tell DataTables not to try and source the data from anywhere. Otherwise it will use the column index (0 in this case).this
在第一列中添加:data:null,告訴數據表不要嘗試從任何地方獲取數據。不然,它將使用列索引(在本例中爲0)。spa