jqgrid自定义格式器也适用于摘要 [英] jqgrid custom formatter getting applied for summary also

查看:76
本文介绍了jqgrid自定义格式器也适用于摘要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jqGrid v5.0.2来实现自定义格式化程序..我在各列中启用了摘要.如果列值大于40,我想以红色显示文本.我已经实现了Oleg针对我的问题的解决方案.格式有效,但是它也也应用于摘要行.例如:

I'm using jqGrid v5.0.2 to implement custom formatter. I'm having summaries enabled in the columns. I want to display the text in Red, if the column value is greater than 40. I have implemented Oleg's solution to my problem. The formatting works, but it is getting applied to the summary row also. For Example :

Resource    Week1
--------    -----
Mr.X         45
  -Task1     25
  -Task2     20

1)在上面的示例中,我只希望值20和25的单元格为红色(如果它们分别大于40),但分组单元格45也显示为红色.我希望分组单元格为红色仅当它高于80(40 + 40)时.关于如何达到预期效果的任何建议吗?

1) In the above example I only want the cells with values 20 and 25 to be red (If they are individually above 40), but the grouped cell 45 also is displayed in red.I want the grouped cell to be red only if it is above 80(40+40). Any suggestions on how to achieve my desired result ?

我的代码:

{
            name: "FirstWeek",
            editable: true,
            sortable: false,
            formatter: function (cellvalue) {
                var color;
                var val = Number(cellvalue);
                if (val > 40) {
                    color = 'red';
                }
                var cellHtml = "<span style='color:" + color + "' originalValue='" +
                             val + "'>" + val + "</span>";
                return cellHtml;
            },

            unformatter: function(cellValue, options, cellObject) {
                    return $(cellObject.html()).attr("originalValue");
                },

                summaryTpl: "<b>{0}</b>",
                summaryType: "sum",
                editrules: { number: true, minValue: 0, maxValue: 40 }
            }

2)内联编辑自定义格式的单元格时,我在单元格(UI)中得到了<span class="cellWithoutBackground" style="color:undefined;">25</span>.我也使用了unformatter函数,这似乎行不通.帮助表示赞赏.

2)While inline editing the custom formatted cell, I'm getting <span class="cellWithoutBackground" style="color:undefined;">25</span> in the cell(UI) . I have used the unformatter function also.That doesn't seem to work. Help appreciated.

推荐答案

我建议您删除formatterunformatter回调,并在该列中使用cellattr回调.可以这样定义:

I recommend you to remove formatter and unformatter callbacks and to use cellattr callback instead in the column. It could be defined like:

cellattr: function(rowId, val, rawObject) {
    if (Number(val) > 40) {
        return " style='color: red'";
    }
}

或类似的

cellattr: function(rowId, val, rawObject) {
    if (Number(val) > 40) {
        return " class='my-text-color'";
    }
}

在列的特定单元格(<td>元素)上设置类my-text-color的位置.如果使用class属性,则应定义其他CSS规则,例如

where you set class my-text-color on specific cells (<td> elements) of the column. If you use class attribute then you should define additional CSS rule like

.my-text-color {
    color: red;
}

这篇关于jqgrid自定义格式器也适用于摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆