问题
I have a jqgrid and on footer there are total values displaying. I want to convert the color of negative values to red. How can I do that?
回答1:
If you use false
as the last parameter of footerData
the data will be not formatted by jqGrid. So you can use HTML fragments like <span style="color:red">...</span>
to change the color of displayed data. Alternatively you can use jQuery CSS Framework classes like ui-state-error
to hightlight the text (see the answer).
If you need still format the summary value you can use $.fmatter.util.NumberFormat
(see the answer or this one) or use formatter
method like in the demo
which uses
footerrow: true,
loadComplete: function () {
var $self = $(this),
sum = $self.jqGrid("getCol", "amount", false, "sum"),
i,
iCol = $("#" + $.jgrid.jqID(this.id) + "_" + "amount")[0].cellIndex, // get index of "amount" column
sumFormatted = this.formatter("", sum, iCol);
$self.jqGrid(
"footerData",
"set",
{
invdate: "Total:",
amount: sum < 0 ? "<span style='color:red'>" + sumFormatted + "</span>": sum
},
false
);
}
来源:https://stackoverflow.com/questions/19240335/how-can-i-change-the-color-of-footer-data-of-jqgrid