如何根据列值将样式应用于 Jquery 数据表列 [英] How to apply style to the Jquery datatable column depending on the column value
本文介绍了如何根据列值将样式应用于 Jquery 数据表列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
http://jsfiddle.net/ktdj3u9r/5/
我正在使用 Jquery DataTable 以表格格式显示数据.
I am uisng Jquery DataTable to display data in a Tabular format .
我的要求是,如果数量字段大于100000,我想以绿色显示
My requirement is that if the quantity field is greater than 100000 , i want to display it in green color
这是我的代码
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;
}
}
]
} );
})
你能告诉我怎么做吗??
could you please let me know how to do this ??
推荐答案
使用 createdCell
数量声明中的回调:
Use the createdCell
callback in yor quantity declaration :
...
"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/
forked fiddle -> http://jsfiddle.net/5fbo72rm/
这篇关于如何根据列值将样式应用于 Jquery 数据表列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文