制表符:在 'cellEdited' 事件上重新格式化单元格
Tabulator: reformat cell on 'cellEdited' event
我是新手 Tabulator.js 但我愿意深入学习和使用它。我确实在为主项目寻找一个好的 tableGenerator 库。到目前为止,它似乎还不错。
我目前使用的是 CND link 版本 5.0.7.
现在这是我的问题:我尝试根据单元格值使用 background-color
格式化单元格(单元格名称是状态,值可以是 true
或 false
).它在创建 table 时起作用。但是如果我之后更改单元格值,它就不起作用了。
我创建了一个名为 statusFormatter
的方法:
statusFormatter: (cell) => {
if (cell.getValue() == true) {
cell.getElement().style.backgroundColor = "#A6A6DF";
}
return cell.getValue();
},
我在 cellEdited
事件上调用此方法:
mainTable.on("cellEdited", function (cell) {
clientTabulator.statusFormatter(cell);
});
我想方法中的 return 有问题。但是我不知道要return什么是我需要的样式。
希望有人能帮忙...
将您的 statusFormatter
函数更改为
statusFormatter: function (cell, formatterParams, onRendered) {
let position = cell.getRow().getPosition();
// switch row even and odd color
let backgroundColor = cell.getValue() ? "#A6A6DF" : position % 2 ? "#efefef" : "#fff";
cell.getElement().style.backgroundColor = backgroundColor;
return cell.getValue();
}
我是新手 Tabulator.js 但我愿意深入学习和使用它。我确实在为主项目寻找一个好的 tableGenerator 库。到目前为止,它似乎还不错。 我目前使用的是 CND link 版本 5.0.7.
现在这是我的问题:我尝试根据单元格值使用 background-color
格式化单元格(单元格名称是状态,值可以是 true
或 false
).它在创建 table 时起作用。但是如果我之后更改单元格值,它就不起作用了。
我创建了一个名为 statusFormatter
的方法:
statusFormatter: (cell) => {
if (cell.getValue() == true) {
cell.getElement().style.backgroundColor = "#A6A6DF";
}
return cell.getValue();
},
我在 cellEdited
事件上调用此方法:
mainTable.on("cellEdited", function (cell) {
clientTabulator.statusFormatter(cell);
});
我想方法中的 return 有问题。但是我不知道要return什么是我需要的样式。
希望有人能帮忙...
将您的 statusFormatter
函数更改为
statusFormatter: function (cell, formatterParams, onRendered) {
let position = cell.getRow().getPosition();
// switch row even and odd color
let backgroundColor = cell.getValue() ? "#A6A6DF" : position % 2 ? "#efefef" : "#fff";
cell.getElement().style.backgroundColor = backgroundColor;
return cell.getValue();
}