How to show nested colModel data in PQGrid?

136 Views Asked by At

I am using PQGrid to show data from a json response. Contents of the json response looks like:

{
  "data": [
    {
      "AAA":{
          "A1":2000,
          "A2":2000,
          "A3":4000 
      },
      "BBB":{
          "B1":2800,
          "B2":2100,
          "B3":4900 
      },      
      "CCC": 1600,
    },
    {
      "AAA":{
          "A1":2000,
          "A2'23":2000,
          "A3":4000 
      },
      "BBB":{
          "B1":2800,
          "B2":2100,
          "B3":4900 
      },      
      "CCC": 1400,
    }
 ]
}
  1. When I try to access the json data, the values with Keys A1,A2,A3,B1,B2,B3 are not displayed. But CCC dataIndx is being displayed.
var colM = [ 
            { title: "AAA", width: 30, dataType: "float", dataIndx: "AAA",
                colModel: [
                    {
                        title: "A1",
                        dataIndx: "A1"
                    },
                    {
                        title: "A2",
                        dataIndx: "A2"
                    },
                    {
                        title: "A3",
                        dataIndx: "A3"
                    }
                ]
            },
            { title: "BBB", width: 30, dataType: "float", dataIndx: "AAA",
                colModel: [
                    {
                        title: "B1",
                        dataIndx: "B2"
                    },
                    {
                        title: "B2",
                        dataIndx: "B2"
                    },
                    {
                        title: "B3",
                        dataIndx: "B3"
                    }
                ]
            },
            { title: "CCC", width: 30, dataIndx: "CCC"}
        ]
  1. I want to show the total value of the column CCC, so I am using the summary property. Till here I am good, but when I collapse the row, the output is like (1600+1400) : 'Sum 3000'. I just want to display the text as '3000'. And this Sum is displayed when the row is minimized, when it is expanded it gets removed. Is there any property which I can use to keep showing the Sum even when the row is expanded.
colModel: [
                    {
                        title: "CCC",
                        dataIndx: "CCC",
                        format: '##,###.00',
                        dataType: "float",
                        summary: { type: "sum"}
                    }, 
           ...
         ]

Need suggestion or help on how to achieve this.

1

There are 1 best solutions below

0
On

For #2: Removing Sum from the Summary in Grouped Row:

Had to add below line: (generic for Average, Count, Max, Min and Sum) summaryTitle: { avg: "{0}", count: '{0}', max: "{0}", min: "{0}", sum: "{0}" },

By Default it was: { avg: "Avg: {0}", count: 'Count: {0}', max: "Max: {0}", min: "Min: {0}", sum: "Sum: {0}" }