带有json数据的EXTJS Pivot Grid

时间:2015-09-29 05:51:19

标签: javascript json extjs ext.net

我是EXTJS的新手。现在我试图开发简单的枢轴网格示例。我的代码是:

  Ext.onReady(function () {
  var myStore = new Ext.data.ArrayStore({
    autoLoad: true,
    fields: ['gender',
        { name: 'birthDecade', type: 'int' },
        { name: 'peoples', type: 'int' }
    ],

    url: 'countries.json'
});
var pivotGrid = new Ext.grid.PivotGrid({
    title: 'Number of people born per decade',
    width: 600,
    height: 91,
    renderTo: 'docbody',
    store: myStore,
    aggregator: 'count',

    topAxis: [
        {
            width: 80,
            dataIndex: 'birthDecade'
        }
    ],
    leftAxis: [
        {

            dataIndex: 'gender'
        }
    ],


});

});

JSON DATA:

 [["Male","2010","1"],
 ["Female","1940","2"],
 ["Male","1960","3"],
 ["Female","1980","4"],
 ["Female","2000","5"],
 ["Male","2010","5"],
 ["Male","2030","6"],
 ["Female","1000","7"]]

输出是: enter image description here

但我想显示我在json中给出的数据(第3栏。值-1,2,3,4,5,6,7)。怎么实现呢?。提前谢谢。

1 个答案:

答案 0 :(得分:0)

正如你使用计数作为聚合器,它的表现就像那样。在2000年,有一位女性在场。同样在2010年有两排男性计数。所以它就是这样表现出来的。 如果你想在输出中显示一些数字,你可以这样使用,

Ext.onReady(function () {
var myStore = new Ext.data.ArrayStore({
    autoLoad: true,
    fields: ['gender',
        { name: 'birthDecade', type: 'int' },
        { name: 'peoples', type: 'int' }
    ],

    url: 'countries.json'
});
var pivotGrid = new Ext.grid.PivotGrid({
    title: 'Number of people born per decade',
    width: 600,
    height: 91,
    renderTo: 'docbody',
    store: myStore,
    aggregator: 'sum',
    measure: 'peoples',

    topAxis: [
        {
            width: 80,
            dataIndex: 'birthDecade'
        }
    ],
    leftAxis: [
        {

            dataIndex: 'gender'
        }
    ],


});

});