在使用datatable的时候,有时候会用到合并多列的情况,在datatable中添加drawCallback属性即可,函数中的内容如:
"drawCallback":function (settings) {
var api =this.api();
var rows =api.rows({page:'current'}).nodes();
var idx =0;// 第一列进行合并
var last =null;
var tr =null;
var ltd =null;
api.column(idx, {page:'current'}).data().each(function (group, i) {
tr =$(rows[i]);
var td =$("td:eq(" +idx +")",tr);
if (last !== group) {
td.attr("rowspan",1);
td.text(group);
ltd =td;
last = group;
td.css("vertical-align","middle");
}else {
ltd.attr("rowspan",parseInt(ltd.attr("rowspan")) +1);
td.remove();
console.log(td.text())
}
});
},
效果图
网友评论