问题描述:

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".

网友答案:

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/.

相关阅读:
Top