可直接在columns申明中對應列下方使用render改變該列樣式
也可單獨在columnsDefs中用targets指定目標。
"render":function(data,type,row,meta){}
完整的為4個參數,其中參數數量是可變的。
data指該行獲取到的該列數據,
row指該行,可用row.name或row[2]獲取第3列字段名為name的值,
type調用數據類型,可用類型“filter”,"display","type","sort",具體用法還未研究,
meta包含請求行索引,列索引,tables各參數等信息。
實例1:(在genre列生成下拉列表形式並綁定控制器傳來的數據)
"columns": [
{"data": "actual_id"},
{"data": "sort_index"},
{"data": "category"},
{"data": "genre",
"render":function(data,type,row,full){
if(data.length!=0){
var str;
for(var i=0;i<data.length;i++){
str+="<option value="+data[i].id+">"+data[i].name+"</option>";
}
return "<select id="+row.sort_index+">"+str+"</select>";
}else{
return "<select id="+row.sort_index+"></select>";
}
}
},
{"data": "created_at"},
{"data": "operation","width":"18%",},
{"data":null}
],
實例2:靜態綁定
columnDefs:{
"targets":3,
"data":null,
"render":function(){}
}