You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AngularJS UI Grid导出PDF时货币符号显示为null问题求助

问题描述

在.NET Core MVC 5项目中开发AngularJS UI Grid时,将表格数据导出为PDF文档时,Total和Discount列的货币符号显示为null。

表格显示效果:
表格显示效果

PDF导出效果:
PDF导出效果

解决方案

出现该问题的核心原因是:UI Grid的PDF导出模块不会自动继承列配置里的cellFilter,尤其是currency过滤器未指定明确货币符号时,导出过程无法正确获取默认本地化符号,导致显示null。以下两种方案可解决该问题:

方案1:自定义导出字段回调函数

在gridOptions中添加exporterFieldCallback,手动为指定字段添加货币符号并格式化数值:

$scope.gridOptions = {
    // 保留原有所有配置
    exporterFieldCallback: function(grid, row, col, input) {
        // 对Total和Discount列进行格式化
        if (col.field === 'Total' || col.field === 'Discount') {
            // 替换为你需要的货币符号,比如'¥'或'€'
            return '$' + parseFloat(input).toFixed(2);
        }
        return input;
    },
    // 其他原有配置...
};

方案2:为列配置导出专用过滤器

在Total和Discount列的columnDefs中添加exporterCellFilter,明确指定货币符号和小数位数:

// Total列修改后
{
    field: 'Total',
    width: '10%',
    cellFilter: 'currency',
    exporterCellFilter: 'currency:"$":2', // 第一个参数是货币符号,第二个是小数位数
    cellClass: 'gridcell-text-right',
    filters: [
        {
            condition: uiGridConstants.filter.GREATER_THAN_OR_EQUAL,
            placeholder: 'greater than or equal'
        },
        {
            condition: uiGridConstants.filter.LESS_THAN_OR_EQUAL,
            placeholder: 'less than or equal'
        }
    ]
},
// Discount列修改后
{
    field: 'Discount',
    width: '10%',
    cellFilter: 'currency',
    exporterCellFilter: 'currency:"$":2',
    cellClass: 'gridcell-text-right',
    filters: [
        {
            condition: uiGridConstants.filter.GREATER_THAN_OR_EQUAL,
            placeholder: 'greater than or equal'
        },
        {
            condition: uiGridConstants.filter.LESS_THAN_OR_EQUAL,
            placeholder: 'less than or equal'
        }
    ]
}

内容的提问来源于stack exchange,提问作者JagathNalin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 22:20:57