Jqgrid中的计算列 [英] Calculated Column in Jqgrid

查看:404
本文介绍了Jqgrid中的计算列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下网格-

https://jsfiddle.net/ht94wbtr/1/

请参见下图

在此网格中,我希望有一个计算出的总红细胞"列,如下面的示例图像所示

in this Grid, i want to have a calculated column 'Total Red Cells' like below sample image

在Oleg先生的帮助下,我得到了下面的代码,该代码可用于Footer

with the help of Oleg sir, i got this below code which can be used for Footer

        var errorInfo = {id: "Errors:", color_name: 0, character_name: 0};
    var i, item;
    for (i = 0; i < mydata.length; i++) {
        item = mydata[i];

        if ($.inArray(item.color_name, hilightcolorcell) < 0) {
            errorInfo.color_name++;
        }
        if ($.inArray(item.character_name, hilightcahractercell) < 0) {
            errorInfo.character_name++;
        }
    }

        footerrow: true,
        userDataOnFooter: true,
        userData: errorInfo //{ id: "Errors:", color_name: 2, character_name: 2 }

我想知道如何遍历color_name和character_name列,并在计算出的列"Total Red Cells"中显示总错误计数,如示例图像所示.请帮忙.

i would like to know how to loop through color_name and character_name columns and display the total error count in a calculated column 'Total Red Cells' as shown in the sample image. please help.

推荐答案

如果我正确理解了您的需求,那么解决方案将非常简单.首先,需要定义要保留/显示总红格"信息的列.让我们将该列命名为redtotal.然后,应扩展errorInfo来保存具有相应值的redtotal属性.相应的代码可能类似于errorInfo

If I correctly understand what you need then the solution would be very easy. First of all you need define the column where you will be hold/display the "Total red cells" information. Let us the column have the name redtotal. Then you should extend errorInfo to hold redtotal property with the corresponding value. The corresponding code could be like errorInfo

var errorInfo = {id: "Errors:", redtotal: 0, color_name: 0, character_name: 0};
var i, item;
for (i = 0; i < mydata.length; i++) {
    item = mydata[i];

    if ($.inArray(item.color_name, hilightcolorcell) < 0) {
        errorInfo.color_name++;
        errorInfo.redtotal++;
    }
    if ($.inArray(item.character_name, hilightcahractercell) < 0) {
        errorInfo.character_name++;
        errorInfo.redtotal++;
    }
}

您将在 https://jsfiddle.net/OlegKi/ht94wbtr/4/上看到结果

这篇关于Jqgrid中的计算列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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