Number of rows are frozen at the bottom of grid depending upon the number of rows in summaryData option.
In this example summaryData option is calculated in custom function that returns 2 rows.

Summary is refreshed whenever:

Summary of rows
Rank
Company
Revenues
Profits
Expenditure = Revenues - Profits
 
 
 
 
 
 
 
 
 
1Exxon Mobil$339,938.00$36,130.00$303,808.00
2Wal-Mart Stores$315,654.00$11,231.00$304,423.00
3Royal Dutch Shell$306,731.00$25,311.00$281,420.00
4BP$267,600.00$22,341.00$245,259.00
5General Motors$192,604.00-$10,567.00$203,171.00
6Chevron$189,481.00$14,099.00$175,382.00
7DaimlerChrysler$186,106.30$3,536.30$182,570.00
8Toyota Motor$185,805.00$12,119.60$173,685.40
9Ford Motor$177,210.00$2,024.00$175,186.00
10ConocoPhillips$166,683.00$13,529.00$153,154.00
11General Electric$157,153.00$16,353.00$140,800.00
12Total$152,360.70$15,250.00$137,110.70
13ING Group$138,235.30$8,958.90$129,276.40
14Citigroup$131,045.00$24,589.00$106,456.00
15AXA$129,839.20$5,186.50$124,652.70
16Allianz$121,406.00$5,442.40$115,963.60
17Volkswagen$118,376.60$1,391.70$116,984.90
18Fortis$112,351.40$4,896.30$107,455.10
19Crédit Agricole$110,764.60$7,434.30$103,330.30
20American Intl. Group$108,905.00$10,477.00$98,428.00
Total:  $3,608,249.10$229,733.00 
Average:  $180,412.46$11,486.65 
Loading...


86
 
1
2
    $(function () {        
3
        var arrayData = [
4
            [1, 'Exxon Mobil', 339938.0, 36130.0],
5
            [2, 'Wal-Mart Stores', 315654.0, 11231.0],
6
            [3, 'Royal Dutch Shell', 306731.0, 25311.0],
7
            [4, 'BP', 267600.0, 22341.0],
8
            [5, 'General Motors', 192604.0, -10567.0],
9
            [6, 'Chevron', 189481.0, 14099.0],
10
            [7, 'DaimlerChrysler', 186106.3, 3536.3],
11
            [8, 'Toyota Motor', 185805.0, 12119.6],
12
            [9, 'Ford Motor', 177210.0, 2024.0],
13
            [10, 'ConocoPhillips', 166683.0, 13529.0],
14
            [11, 'General Electric', 157153.0, 16353.0],
15
            [12, 'Total', 152360.7, 15250.0],
16
            [13, 'ING Group', 138235.3, 8958.9],
17
            [14, 'Citigroup', 131045.0, 24589.0],
18
            [15, 'AXA', 129839.2, 5186.5],
19
            [16, 'Allianz', 121406.0, 5442.4],
20
            [17, 'Volkswagen', 118376.6, 1391.7],
21
            [18, 'Fortis', 112351.4, 4896.3],
22
            [19, 'Crédit Agricole', 110764.6, 7434.3],
23
            [20, 'American Intl. Group', 108905.0, 10477.0]
24
        ];
25
        //calculate sum of 3rd and 4th column.
26
        function calculateSummary() {
27
            var revenueTotal = 0,
28
                profitTotal = 0,
29
                data = grid? grid.option('dataModel.data'): arrayData; 
30
31
            for (var i = 0; i < data.length; i++) {
32
                var row = data[i];
33
                revenueTotal += (row[2] * 1);
34
                profitTotal += (row[3] * 1);
35
            }
36
37
            var revenueAverage = (revenueTotal / data.length),
38
                profitAverage = (profitTotal / data.length),
39
                totalData = ["<b>Total: </b>", "", revenueTotal, profitTotal],
40
                averageData = ["<b>Average: </b>", "", revenueAverage, profitAverage];
41
42
            return [totalData, averageData]; //2 dimensional array.
43
        }
44
        var obj = {
45
            width: 'flex',
46
            flex: { one: true },
47
            height: 400,
48
            numberCell: { show: false },
49
            title: "Summary of rows",
50
            filterModel: { on: true, header: true },
51
            colModel: [
52
                { title: "Rank", dataType: "integer" },
53
                { title: "Company",
54
                    filter: { type: 'textbox', condition: 'contain', listeners: ['keyup'] }
55
                },
56
                { title: "Revenues", dataType: "float", format: '$##,###.00',
57
                    validations: [{ type: 'nonEmpty', msg: 'Required'}]
58
                },
59
                { title: "Profits", dataType: "float", format: '$##,###.00',
60
                    validations: [{ type: 'nonEmpty'}]
61
                },
62
                {//formula field.
63
                    title: "Expenditure = Revenues - Profits",
64
                    dataType: "float", 
65
                    format: '$##,###.00',
66
                    editable: false,
67
                    formula: function (ui) {
68
                        var rd = ui.rowData;
69
                        return rd[2] - rd[3];
70
                    }
71
                }
72
            ],
73
            dataModel: { data: arrayData },
74
            summaryData: calculateSummary(),
75
            cellSave: function () {
76
                this.refresh();
77
            }
78
        };
79
        var grid = pq.grid("#grid_summary", obj);
80
81
        //refresh summary upon change in data and filtering.
82
        grid.on('change filter', function () {
83
            this.option('summaryData', calculateSummary());
84
        });
85
    });
86