官网的网址是:http://www.datatables.net/examples/advanced_init/column_render.html
内容很好理解。例子代码也不复杂,如下:
$(document).ready(
function
()
{
$(
'#example'
).dataTable(
{
"columnDefs"
:
[
{
//
The `data` parameter refers to the data for the cell (defined by the
//
`data` option, which defaults to the column being worked with, in
//
this case `data: 0`.
"render"
:
function
(
data, type, row ) {
return
data
+
'
('
+
row[3]
+
')'
;
请注意红色字体部分
},
"targets"
:
0
},
{
"visible"
:
false
,
"targets"
:
[ 3 ] }
]
}
);
}
);
请注意上面的红色字体部分,row[3],3代表这一列的索引位置。这里推荐大家用列的名称,而不要用列的索引,比较好。因为,如果你载入的后台是多个字段,但前台显示限量个字段,并且有的字段的值为null。这时,如果用列索引,则会显示undefine。