对页脚行使用自定义格式化程序 [英] Using custom formatter for footer row

查看:53
本文介绍了对页脚行使用自定义格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向页脚行添加一些数据,该数据不能被该列的预定义格式化程序正确格式化.例如:

I want to add some data to the footer row, which cannot be formatted correctly by the pre-defined formatter of that column. for example :

ColumnModel

ColumnModel

{
  'name': 'GDP',
  'label': 'GDP',
  'formatter': 'currency',
  'formatOptions': {
    'decimalPlaces': 2,
    'defaultValue': '',
    "thousandsSeparator": ',',
    'prefix': '$'
  },

}

,但页脚的用户数据类似于{"GDP":"Total- 1233"},并且该页脚单元格显示空白值.我的猜测是它期望数值数据.有没有一种方法可以为此列页脚分配自定义格式程序?如果有,该自定义格式化程序可以为"Total- 1233"中的数字部分调用预定义的currency格式化程序吗?

but the userdata for footer is like {"GDP":"Total- 1233"} and blank value is displayed for that footer cell. My guess is that it expects numerical data. Is there a way to assign a custom formatter for this column footer? If there is, can that custom formatter invoke pre-defined currency formatter for the number part in "Total- 1233"?

推荐答案

在这种情况下,您需要加载列表,其中包含footerrow和userDataOnFooter选项,如下所示:

In this case, you need load list with the options of footerrow and userDataOnFooter like below:

footerrow : true,    
userDataOnFooter : false, 

您在上面将userDataOnFooter选项标记为'false',因此您应该在'loadComlpete','gridComplete'或依赖于代码逻辑的任何其他自定义函数中手动加载userdata.您可以按照以下代码手动将用户数据加载到页脚行,这里以"loadComplete"为例:

You mark userDataOnFooter option as 'false' above, so you should load userdata manually in customed function of 'loadComlpete', 'gridComplete' or any one else which depends your code logic. You can code as below to manually load userdata to footer row, here I use 'loadComplete' for example:

loadComplete:function(){
    var uData = jQuery("#tableId").jqGrid('getGridParam', 'userData' );

    // Notice that be sure pass false to the last parameter of function,
    // or jqGrid will use formatter defined in colModel option
    // which in your case is 'currency' for GDP column.
    jQuery("#tableId").jqGrid("footerData", "set", uData, false);
}  

此外,获取用户数据的方法在jqGrid的旧版本和新版本之间是不同的.我在下面为您提供了屏幕截图:

Besides, the method to get userdata is diffirent between old version and new versioin of jqGrid. I got a screenshot for you below:

希望对您有用. :)

这篇关于对页脚行使用自定义格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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