paramQuery (PQGrid) Добавить SummaryData внизу - PullRequest
0 голосов
/ 22 апреля 2020

Я использую сетку Paramquery с версией 6.0.0 И хочу добавить сводку внизу. Я нашел пример на официальном сайте, как показано ниже. введите описание изображения здесь Это именно то, что я хочу.

$(function () {
var json_data = [
    {"rank": 1, "company": "Exxon Mobil","revenues": 10, "profits": 1 },
    {"rank": 2,"company": "Wal-Mart Stores","revenues": 11,"profits": 2  },
    {"rank": 3,"company": "Royal Dutch Shell","revenues": 12,"profits": 3 },
    {"rank": 4,"company": "BP","revenues": 13, "profits": 4 },
    {"rank": 5, "company": "General Motors", "revenues": 14, "profits": 5},
    {"rank": 6, "company": "Chevron", "revenues": 15, "profits": 6},
    {"rank": 7, "company": "DaimlerChrysler", "revenues": 16, "profits": 7},
    {"rank": 8, "company": "Toyota Motor", "revenues": 17, "profits": 8 },
    { "rank": 9, "company": "Ford Motor", "revenues": 18, "profits": 9 },
    { "rank": 10, "company": "ConocoPhillips", "revenues": 19, "profits": 10},
    { "rank": 11, "company": "General Electric", "revenues": 20, "profits": 11 },
    { "rank": 12, "company": "Total", "revenues": 21, "profits": 12 },
    { "rank": 13, "company": "ING Group", "revenues": 22, "profits": 13},
    { "rank": 14, "company": "Citigroup", "revenues": 23, "profits": 14 },
    { "rank": 15, "company": "AXA", "revenues": 24, "profits": 15 },
    { "rank": 16, "company": "Allianz", "revenues": 25, "profits": 16 },
    { "rank": 17, "company": "Volkswagen", "revenues": 26, "profits": 17 },
    { "rank": 18, "company": "Fortis", "revenues": 27, "profits": 18 },
    { "rank": 19, "company": "Crédit Agricole","revenues": 28,"profits": 19},
    { "rank": 20, "company": "American Intl. Group", "revenues": 29, "profits": 20 }
];

var obj = { 
    width: "flex",        
    showTitle: false,
    height: 400,        
    flex: {one: true},        
    menuIcon: true,  
    toolbar: {
        items: [{
            type: 'select',
            label: 'Format: ',                
            attr: 'id="export_format"',
            options: [{ xlsx: 'Excel', csv: 'Csv', htm: 'Html', json: 'Json'}]
        },
        {
            type: 'button',
            label: "Export",
            icon: 'ui-icon-arrowthickstop-1-s',
            listener: function () {
                this.exportData({
                    url: "/pro/demos/exportData",
                    format: $("#export_format").val(),
                    zip: false,
                    render: true
                });
            }
        }]
    },
    colModel: [
        { title: "Rank", dataType: "integer", dataIndx: "rank",  exportRender: false,
            render: function(ui){
                if( ui.rowData.summaryRow ){
                    return "<b>"+ui.cellData+"</b>";
                }
            }
        },
        { title: "Company", dataIndx: "company" },
        { title: "Revenues", dataType: "float", dataIndx: "revenues", format: '$##,###.00' },
        { title: "Profits", dataType: "float", dataIndx: "profits", format: '$##,###.00' },
        {//formula field.
            title: "Expenditure = Revenues - Profits",
            dataType: "float", 
            dataIndx: 'diff',
            format: '$##,###.00',
            editable: false
        }
    ],
    summaryData: [
        { rank:'Total', summaryRow: true, revenues:'test', profits:'test2'},
        { rank:'Average', summaryRow: true, revenues:'test', profits:'test2'},            
        { rank:'Std deviation', summaryRow: true, revenues:'test', profits:'test2'}                
    ],            
    formulas: [
        ["diff", function(rd){
            return rd.revenues - rd.profits;
        }]
    ],
    dataModel: { data: json_data }
};

pq.grid("#grid_summary", obj);

});

Но проблема в том, что у меня есть сгруппированные столбцы, подобные этому

colModel: [
    { title: "Rank", dataType: "integer", dataIndx: "rank",  exportRender: false,
        render: function(ui){
            if( ui.rowData.summaryRow ){
                return "<b>"+ui.cellData+"</b>";
            }
        }
    },
    { title: "Company", dataIndx: "company" },
    { title: "Revenues", dataType: "float", dataIndx: "revenues", format: '$##,###.00' },
    { title: "Profits", dataType: "float", dataIndx: "profits", format: '$##,###.00' },
    { title: "group", dataIndx: "group", colModel :[
          { title: "group_1" ,dataIndx: "group_1"},
          { title: "group_1" ,dataIndx: "group_1"}
    ]}
]

Я не могу отобразить сводку, для которой dataIndx равен "group_1" и "group_2". Я пытаюсь использовать

summaryData: [
        { rank:'Total', summaryRow: true, revenues:'test', profits:'test2', group_1: 'test',group_2:'test'},
        { rank:'Total', summaryRow: true, revenues:'test', profits:'test2', group_1: 'test',group_2:'test'},            
        { rank:'Total', summaryRow: true, revenues:'test', profits:'test2', group_1: 'test',group_2:'test'}                
    ]

ИЛИ

summaryData: [
        { rank:'Total', summaryRow: true, revenues:'test', profits:'test2', group:{group_1: 'test',group_2:'test'}},
        { rank:'Total', summaryRow: true, revenues:'test', profits:'test2', group:{group_1: 'test',group_2:'test'}},            
        { rank:'Total', summaryRow: true, revenues:'test', profits:'test2', group:{group_1: 'test',group_2:'test'}}                
    ]

Но ничего не отображается.

Что мне делать с этим делом?

...