http://jsfiddle.net/ktdj3u9r/5/
我使用Jquery DataTable以表格格式显示数据。
我的要求是,如果数量字段大于100000,我想以绿色显示
这是我的代码
var dataSet =
[
[
"1441.75",
"238469"
],
[
"1614.45",
"327663"
],
[
"834.15",
"1583726"
],
[
"2261.85",
"1062354"
],
[
"444.10",
"99399"
]
];
var array_names = ["A", "B", "C", "D", "E"];
for(var key in dataSet) {
if(dataSet.hasOwnProperty(key)) {
//dataSet[key].unshift(array_names[key]);
dataSet[key].splice(0,0,array_names[key]);
}
}
$(function()
{
$('#allwl').dataTable( {
"iDisplayLength": -1,
"data": dataSet,
"columns": [
{ "title": "Name" },
{ "title": "Price" },
{
"title": "Quantity" ,
mRender: function(data, type, row){
var quantity = row[2] ;
return quantity;
}
}
]
} );
})
你能告诉我怎么做吗??
答案 0 :(得分:1)
在您的数量声明中使用createdCell
回调:
...
"columns": [
{ "title": "Name" },
{ "title": "Price" },
{ "title": "Quantity" ,
mRender: function(data, type, row){
var quantity = row[2] ;
return quantity;
},
createdCell: function (td, cellData, rowData, row, col) {
if (cellData>100000) $(td).css('color', 'green');
}
}
]
...
分叉小提琴 - >的 http://jsfiddle.net/5fbo72rm/ 强>
答案 1 :(得分:0)
使用fnRowCallback
:
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
if(aData[2] > 100000){
$('td:eq(2)', nRow).addClass("td-green");
}
}
这会将课程td-green
添加到任何值> 100000