根据 Dynatable 中的行值对行着色
Coloring rows based on row values in Dynatable
我正在尝试根据 "Status" 为行着色,可以是 Red/Green。
使用 dynatable 根据 JSON 数据生成 table 行。
问题是每当我从 dynatable 调用以下代码时,它总是被 dyntable.process();
覆盖
$('#mytable tr td').each(function() {
if ($(this).text() == 'Red') {
$(this).closest('tr').css('background-color', '#f00');
}
});
我的index.php:
http://pastie.org/10389654
我的index.js:
http://pastie.org/10389656
查看文档的这一点:Documentation - Event
并可能使用 dynatable:beforeUpdate
事件
有些方法是这样的:
var dynatable = $('#mytable').dynatable({
dataset: {
ajax: true,
ajaxUrl: './api.php',
ajaxOnLoad: true,
records: []
},
params: {
records: 'data'
},
features: {
paginate: false,
sort: false,
pushState: false,
search: false,
recordCount: false,
perPageSelect: false
}
}).data('dynatable').bind('dynatable:afterProcess', changeColor);
然后是你的函数
function changeColor() {
$('#mytable tr td').each(function() {
if ($(this).text() == 'Red') {
$(this).closest('tr').css('background-color', '#f00');
}
});
}
我正在尝试根据 "Status" 为行着色,可以是 Red/Green。 使用 dynatable 根据 JSON 数据生成 table 行。
问题是每当我从 dynatable 调用以下代码时,它总是被 dyntable.process();
覆盖$('#mytable tr td').each(function() {
if ($(this).text() == 'Red') {
$(this).closest('tr').css('background-color', '#f00');
}
});
我的index.php: http://pastie.org/10389654
我的index.js: http://pastie.org/10389656
查看文档的这一点:Documentation - Event
并可能使用 dynatable:beforeUpdate
事件
有些方法是这样的:
var dynatable = $('#mytable').dynatable({
dataset: {
ajax: true,
ajaxUrl: './api.php',
ajaxOnLoad: true,
records: []
},
params: {
records: 'data'
},
features: {
paginate: false,
sort: false,
pushState: false,
search: false,
recordCount: false,
perPageSelect: false
}
}).data('dynatable').bind('dynatable:afterProcess', changeColor);
然后是你的函数
function changeColor() {
$('#mytable tr td').each(function() {
if ($(this).text() == 'Red') {
$(this).closest('tr').css('background-color', '#f00');
}
});
}