customizeText devextreme 不工作
customizeText devextreme not working
datagrid = $("#gridContainer").dxDataGrid({
columns: [{
dataField: "STCG",
caption: "STCG",
format: 'fixedPoint',
allowFiltering: false,
precision: 2,
customizeText: function(cellElement, cellInfo) {
var fieldData = cellInfo.value;
if (fieldData >= 0) {
cellInfo.cellElement.addClass("greencolortext");
} else {
cellInfo.cellElement.addClass("redcolortext");
}
}
}]
}).dxDataGrid("instance");
.greencolortext {
color: #2DC48D;
}
.redcolortext {
color: #bf4e6a;
}
我正在尝试更改单元格中数据的字体颜色
如果数据大于或等于零,文本将为绿色,否则为红色
参考这个 - dxDataGrid - customizeText does not change cell text under certain conditions
The customizeText callback function is intended for changing the cell
text. If you wish to completely customize your cell content, use only
cellTemplate.
希望对您有所帮助..
customizeText 方法不接受 2 个参数。那么,如果您打开浏览器控制台,您将看到 javascript 个错误。
在您的情况下,您可以使用 cellTemplate 选项:
cellTemplate: function($cell, cellInfo) {
var fieldData = cellInfo.data.STCG;
if (fieldData >= 0) {
$cell.addClass("greencolortext");
} else {
$cell.addClass("redcolortext");
}
$cell.append(cellInfo.text);
}
Demo.
datagrid = $("#gridContainer").dxDataGrid({
columns: [{
dataField: "STCG",
caption: "STCG",
format: 'fixedPoint',
allowFiltering: false,
precision: 2,
customizeText: function(cellElement, cellInfo) {
var fieldData = cellInfo.value;
if (fieldData >= 0) {
cellInfo.cellElement.addClass("greencolortext");
} else {
cellInfo.cellElement.addClass("redcolortext");
}
}
}]
}).dxDataGrid("instance");
.greencolortext {
color: #2DC48D;
}
.redcolortext {
color: #bf4e6a;
}
我正在尝试更改单元格中数据的字体颜色 如果数据大于或等于零,文本将为绿色,否则为红色
参考这个 - dxDataGrid - customizeText does not change cell text under certain conditions
The customizeText callback function is intended for changing the cell text. If you wish to completely customize your cell content, use only cellTemplate.
希望对您有所帮助..
customizeText 方法不接受 2 个参数。那么,如果您打开浏览器控制台,您将看到 javascript 个错误。
在您的情况下,您可以使用 cellTemplate 选项:
cellTemplate: function($cell, cellInfo) {
var fieldData = cellInfo.data.STCG;
if (fieldData >= 0) {
$cell.addClass("greencolortext");
} else {
$cell.addClass("redcolortext");
}
$cell.append(cellInfo.text);
}
Demo.