jqGrid and jqPivot: Keeping spaces in pivoted column names?

混江龙づ霸主 提交于 2019-12-11 09:12:26

问题


I'm using jqGrid with the jqPivot API.

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

eg.

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/

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


回答1:


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, ' ');}
}],

See the modified demo http://jsfiddle.net/OlegKi/aUDHx/970/.



来源:https://stackoverflow.com/questions/26782346/jqgrid-and-jqpivot-keeping-spaces-in-pivoted-column-names

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!