سؤال

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?

هل كانت مفيدة؟

المحلول

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

enter image description here

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
    );
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top