为页脚行使用自定义格式化程序

Using custom formatter for footer row

我想向页脚行添加一些数据,该列的预定义格式化程序无法正确格式化这些数据。例如:

列模型

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

}

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

在这种情况下,您需要使用 footerrow 和 userDataOnFooter 选项加载列表,如下所示:

footerrow : true,    
userDataOnFooter : false, 

您在上面将 userDataOnFooter 选项标记为 'false',因此您应该在 'loadComlpete'、'gridComplete' 或任何其他取决于您的代码逻辑的自定义函数中手动加载用户数据。您可以编写如下代码以手动将用户数据加载到页脚行,这里我使用 'loadComplete' 例如:

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新旧版本获取userdata的方法不同。我在下面为您提供了屏幕截图:

希望对你有用。 :)