summaryData
option.
31
2<div id="grid_summary" style="margin:auto;"></div>
3
921
2$(function () {
3var json_data = [
4{"rank": 1, "company": "Exxon Mobil","revenues": 10, "profits": 1 },
5{"rank": 2,"company": "Wal-Mart Stores","revenues": 11,"profits": 2 },
6{"rank": 3,"company": "Royal Dutch Shell","revenues": 12,"profits": 3 },
7{"rank": 4,"company": "BP","revenues": 13, "profits": 4 },
8{"rank": 5, "company": "General Motors", "revenues": 14, "profits": 5},
9{"rank": 6, "company": "Chevron", "revenues": 15, "profits": 6},
10{"rank": 7, "company": "DaimlerChrysler", "revenues": 16, "profits": 7},
11{"rank": 8, "company": "Toyota Motor", "revenues": 17, "profits": 8 },
12{ "rank": 9, "company": "Ford Motor", "revenues": 18, "profits": 9 },
13{ "rank": 10, "company": "ConocoPhillips", "revenues": 19, "profits": 10},
14{ "rank": 11, "company": "General Electric", "revenues": 20, "profits": 11 },
15{ "rank": 12, "company": "Total", "revenues": 21, "profits": 12 },
16{ "rank": 13, "company": "ING Group", "revenues": 22, "profits": 13},
17{ "rank": 14, "company": "Citigroup", "revenues": 23, "profits": 14 },
18{ "rank": 15, "company": "AXA", "revenues": 24, "profits": 15 },
19{ "rank": 16, "company": "Allianz", "revenues": 25, "profits": 16 },
20{ "rank": 17, "company": "Volkswagen", "revenues": 26, "profits": 17 },
21{ "rank": 18, "company": "Fortis", "revenues": 27, "profits": 18 },
22{ "rank": 19, "company": "Crédit Agricole","revenues": 28,"profits": 19},
23{ "rank": 20, "company": "American Intl. Group", "revenues": 29, "profits": 20 }
24];
25
26var obj = {
27width: "flex",
28showTitle: false,
29height: 400,
30flex: {one: true},
31menuIcon: true,
32change: function () {
33this.refreshSummary();
34},
35toolbar: {
36items: [{
37type: 'select',
38label: 'Format: ',
39cls: "export_format",
40options: [{ xlsx: 'Excel', csv: 'Csv', htm: 'Html', json: 'Json'}]
41},
42{
43type: 'button',
44label: "Export",
45icon: 'ui-icon-arrowthickstop-1-s',
46listener: function () {
47var format = $(".export_format").val(),
48data = this.exportData({
49//url: "/pro/demos/exportData",
50format: format,
51render: true
52});
53pq.saveAs(data, "pqgrid." + format);
54}
55}]
56},
57colModel: [
58{ title: "Rank", dataType: "integer", dataIndx: "rank", exportRender: false,
59render: function(ui){
60if( ui.rowData.summaryRow ){
61return "<b>"+ui.cellData+"</b>";
62}
63}
64},
65{ title: "Company", dataIndx: "company" },
66{ title: "Revenues", dataType: "float", dataIndx: "revenues", format: '$##,###.00' },
67{ title: "Profits", dataType: "float", dataIndx: "profits", format: '$##,###.00' },
68{//formula field.
69title: "Expenditure = Revenues - Profits",
70dataType: "float",
71dataIndx: 'diff',
72format: '$##,###.00',
73editable: false
74}
75],
76summaryData: [
77{ rank:'Total', summaryRow: true, pq_fn:{revenues:'sum(C:C)', profits:'sum(D:D)', diff:'sum(E:E)' }},
78{ rank:'Average', summaryRow: true, pq_fn:{revenues:'average(C:C)', profits:'average(D:D)', diff:'average(E:E)' }},
79{ rank:'Std deviation', summaryRow: true, pq_fn:{revenues:'stdev(C:C)', profits:'stdev(D:D)', diff:'stdev(E:E)' }}
80],
81formulas: [
82["diff", function(rd){
83return rd.revenues - rd.profits;
84}]
85],
86dataModel: { data: json_data }
87};
88
89pq.grid("#grid_summary", obj);
90
91});
92
x1
2tr.green td { background: lightgreen;}
3tr.yellow td { background: yellow;}
4