我使用以下代码动态更新单元格并且工作正常,唯一的方法是如何更改背景的颜色和单元格数据的文本。如果可能的话,也可以举例说明如何更改整行。提前谢谢。
var years = [Int]()
var overlap = [Int]()
var overlapTwice = [Int]()
var overlapThree = [Int]()
for life in people.values {
var birth = Int(life["birth"]!)
var death = Int(life["death"]!)
for year in birth..<death {
if !years.contains(year) {
years.append(year)
} else {
overlap.append(year)
}
}
}
for x in overlap {
if !overlapTwice.contains(x) {
overlapTwice.append(x)
} else {
overlapThree.append(x)
}
}
print(overlapThree)
答案 0 :(得分:5)
您可以使用cell().node()
API方法访问单元节点。
$(document).ready(function (){
var table = $('#example').DataTable();
table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
var cell = table.cell({ row: rowIdx, column: 0 }).node();
$(cell).addClass('warning');
});
});
请参阅this jsFiddle以获取代码和演示。