自定义格式时的JqGrid getCol()总和 [英] JqGrid getCol() sum when custom format

查看:414
本文介绍了自定义格式时的JqGrid getCol()总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JqGrid,其中有一个数据页脚,我想在其中放置列的总和.我还希望当单元格值在网格中等于零时,它将为灰色.为此,我创建了一个自定义格式化程序:

I have a JqGrid whith a data footer where I'd like to put the sum of the column. I'd also like that that when the cell value equal zero in the grid, it will be color in grey. To do so I've creatted a custom formatter:

    currencyFmatter = function (cellValue, options, rowObject) {
    if (cellValue == 0)
        return '<span class="cellWithoutBackground" style="color:#E1E1E1;">' +
            $.fn.fmatter('number', cellValue, options, rowObject)
          + '</span>';
    return $.fn.fmatter('number', cellValue, options, rowObject);
};

我这样称呼

{ name: 'Name', index: 'Name', align: 'center', width: '200px' },
                    { name: 'January', index: 'Months["January"].Amount', align: 'center', 
                      formatter:currencyFmatter}

着色很好,但是数据页脚中的总和不再起作用,它总是显示为0.

The coloration is good but the sum in the data footer don't work anymore it always says 0.

loadComplete: function () {

                var janSum = $('#jqgEndYear').jqGrid('getCol', 'January', false, 'sum');
                var febSum = $('#jqgEndYear').jqGrid('getCol', 'February', false, 'sum');
                var marSum = $('#jqgEndYear').jqGrid('getCol', 'March', false, 'sum');
                var aprSum = $('#jqgEndYear').jqGrid('getCol', 'April', false, 'sum');
                var maySum = $('#jqgEndYear').jqGrid('getCol', 'May', false, 'sum');
                var junSum = $('#jqgEndYear').jqGrid('getCol', 'June', false, 'sum');
                var julSum = $('#jqgEndYear').jqGrid('getCol', 'July', false, 'sum');
                var augSum = $('#jqgEndYear').jqGrid('getCol', 'August', false, 'sum');
                var sepSum = $('#jqgEndYear').jqGrid('getCol', 'September', false, 'sum');
                var octSum = $('#jqgEndYear').jqGrid('getCol', 'October', false, 'sum');
                var novSum = $('#jqgEndYear').jqGrid('getCol', 'November', false, 'sum');
                var decSum = $('#jqgEndYear').jqGrid('getCol', 'December', false, 'sum');

                $('#jqgEndYear').jqGrid('footerData', 'set', { Code: 'Total:',
                    January: janSum,
                    February: febSum,
                    March: marSum,
                    April: aprSum,
                    May: maySum,
                    June: junSum,
                    July: julSum,
                    August: augSum,
                    September: sepSum,
                    October: octSum,
                    November: novSum,
                    December: decSum
                });
            }
        });

如果您对为什么不计算总和有任何想法,请阅读. 预先感谢您的帮助

If you have any idea of why the sum won't calculate, I be pleased to read it. Thanks in advance for your help

推荐答案

您必须定义取消格式化(取消格式化),除了格式化器使方法 getCol 与具有以下内容的列一起使用自定义格式化程序.参见行 ="https://github.com/tonytomov/jqGrid/blob/v4.3.1/js/grid.base.js#L3251-3304" rel ="nofollow"> getCol方法的源代码

You have to define unformat (unformatter) additionally to formatter to make the method getCol working with columns having custom formatter. See the line of the source code of getCol method.

这篇关于自定义格式时的JqGrid getCol()总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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