1

This sample uses jqGrid 4.6:

http://jsfiddle.net/aUDHx/1218/

As one can see, regardless of the number of aggregates, the header names are displayed correctly ("A A", "A B", etc.)

However, when I switch to version 4.7, the pivoted columns aren't named correctly when more than one aggregate is used:

http://jsfiddle.net/aUDHx/1219/

If only one aggregate is used, the headers display correctly.

Does 4.7 have a different method of specifying the header names, or is this a bug? If the latter, does an appropriate workaround exist?

This is the code for the yDimension:

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

The converter function is used to correctly format the header name. This is not required in 4.7 if you only use one aggregate, but anything more than that causes it to break.

"Gurrido" is now the new name of jqGrid.

4

1 回答 1

2

问题在于您在名称中使用的空格。jqPivot目前不支持名称中的空格。例如,您可以通过将空格替换_为(下划线)来解决问题。我在这里描述了解决方法。

顺便说一下,Gurrido jqGrid并不是唯一拥有 MIT 许可证的免费开源 jqGrid 继承者。在启动 Gurrido jqGrid 之后,最后一个免费 jqGrid 的一些其他 jqGrid 分支正在开发中。我在这里发布我的结果。我计划可能在本月发布新版本。你可以在这里找到另一个叉子。一种适用于我在存储库中所做的许多更改,但另一种也进行了一些他自己的更改。

更新:您描述的标签问题是 jqGrid 4.7 中的一个错误。顺便说一句,您不需要使用converter聚合值中的使用空间。

我在我的 jqGrid 存储库发布了错误修复。您可以在演示http://jsfiddle.net/OlegKi/b47ocLd7/上看到结果

在此处输入图像描述

该演示使用以下 JavaScript 代码

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

$("#grid").jqGrid("jqPivot", mydata, {
        xDimension: [
            { isGroupField: false, width: 40, dataName: "id",  label: "ID" },
            { isGroupField: false, width: 80, dataName: "emp", label: "Employee" }
        ],
        yDimension: [
            { dataName: "product" }
        ],
        aggregates: [
            { aggregator: "sum", width: 60, member: "sold",  label: "Sold" },
            { aggregator: "sum", width: 60, member: "sold2", label: "Sold 2" }
        ],
        colTotals: true
    },
    {
        height: "auto",
        pager: "#pager",
        iconSet: "fontAwesome",
        resizeStop: function () {
            $(this).jqGrid("setGridWidth", this.grid.newWidth, false);
        },
        caption: "Daily Sales"
    }
);
于 2015-02-04T19:55:11.847 回答