jqGrid和jqPivot:在透视列名称中保留空格? [英] jqGrid and jqPivot: Keeping spaces in pivoted column names?

查看:102
本文介绍了jqGrid和jqPivot:在透视列名称中保留空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将jqGrid与 jqPivot API 一起使用.

I'm using jqGrid with the jqPivot API.

我遇到的问题是jqPivot从透视列名称中删除了空格.有什么办法可以改变这种行为?

The problem I'm encountering is that jqPivot removes the spaces from the pivoted column names. Is there any way to change this behaviour?

例如

var mydata = [
    {id: "1", emp:"Michelle", product:"A A", sold:"8"},
    {id: "2", emp:"Tania", product:"A A", sold:"3"},
    {id: "6", emp:"Mark", product:"A B", sold:"1"},
    {id: "3", emp:"Tommy", product:"A B", sold:"5"},
    {id: "4", emp:"Dave", product:"B B", sold:"2"},
    {id: "5", emp:"Carol", product:"B B", sold:"5"},
];

var grid = $("#grid");

grid.jqGrid('jqPivot',
    mydata, {
        xDimension: [{
            dataName: 'id',
            label: 'ID',
            width: 90
        }, {
            dataName: 'emp',
            label: 'Employee',
            width: 90
        }, ],
        yDimension: [{
            dataName: 'product'
        }],
        aggregates: [{
            member: 'sold',
            aggregator: 'sum',
            width: 50,
            label: 'Sold'
        }, ],
        colTotals: true

    }, {
        width: "100%",
        height: "100%",
        pager: "#pager",
        caption: "Daily Sales"
    });

http://jsfiddle.net/aUDHx/968/

将"AA"和"AB"列显示为"AA"和"AB"等.

Instead of "A A" and "A B" etc. it displays the columns as "AA" and "AB".

推荐答案

我同意这是一个问题.原因是jqPivot的该行代码.作为一种快速而肮脏的解决方法,我建议您使用转换器将空格替换为其他字符,例如_ ( )或 .

I agree that it's a problem. The reason is the line of jqPivot code. As a quick and dirty workaround I could suggest you to use converter which replace the space to some other character like _,   ( ) or  .

yDimension: [{
    dataName: 'product',
    converter: function (val) {return val.replace(/\s/g, ' ');}
}],

请参阅修改后的演示 http://jsfiddle.net/OlegKi/aUDHx/970/.

这篇关于jqGrid和jqPivot:在透视列名称中保留空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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