remote-group-summary-grid.js
3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Ext.Loader.setConfig({ enabled: true });
Ext.require([
'Ext.grid.*',
'Ext.data.*'
]);
Ext.define('Task', {
extend: 'Ext.data.Model',
idProperty: 'taskId',
fields: [
{name: 'projectId', type: 'int'},
{name: 'project', type: 'string'},
{name: 'taskId', type: 'int'},
{name: 'description', type: 'string'},
{name: 'estHours', type: 'float'},
{name: 'rate', type: 'float'},
{name: 'cost', type: 'float'},
{name: 'due', type: 'date', dateFormat:'m/d/Y'}
]
});
Ext.onReady(function(){
var store = Ext.create('Ext.data.Store', {
model: 'Task',
autoLoad: true,
remoteSort: true,
remoteGroup: true,
proxy: {
type: 'ajax',
url: 'remote-group-summary-grid.php',
reader: {
type: 'json',
root: 'data'
}
},
sorters: {property: 'due', direction: 'ASC'},
groupField: 'project'
});
var grid = Ext.create('Ext.grid.Panel', {
width: 800,
height: 450,
title: 'Sponsored Projects',
renderTo: Ext.getBody(),
store: store,
viewConfig: {
stripeRows: false
},
dockedItems: [{
dock: 'top',
xtype: 'toolbar',
items: [{
text: 'Show Summary',
pressed: true,
enableToggle: true,
toggleHandler: function(btn, pressed){
var view = grid.getView();
view.getFeature('group').toggleSummaryRow(pressed);
view.refresh();
}
}]
}],
features: [{
id: 'group',
ftype: 'groupingsummary',
groupHeaderTpl: '{name}',
hideGroupedHeader: true,
remoteRoot: 'summaryData',
enableGroupingMenu: false
}],
columns: [{
text: 'Task',
flex: 1,
sortable: true,
tdCls: 'task',
dataIndex: 'description',
hideable: false,
summaryRenderer: function(value, summaryData, dataIndex) {
return ((value === 0 || value > 1) ? '(' + value + ' Tasks)' : '(1 Task)');
}
}, {
hideable: false,
header: 'Project',
width: 20,
sortable: true,
dataIndex: 'project'
}, {
header: 'Due Date',
width: 80,
sortable: true,
dataIndex: 'due',
renderer: Ext.util.Format.dateRenderer('m/d/Y')
}, {
header: 'Estimate',
width: 75,
sortable: true,
dataIndex: 'estHours',
renderer: function(value, metaData, record, rowIdx, colIdx, store, view){
return value + ' hours';
},
summaryRenderer: function(value, summaryData, dataIndex) {
return value + ' hours';
}
}, {
header: 'Rate',
width: 75,
sortable: true,
renderer: Ext.util.Format.usMoney,
summaryRenderer: Ext.util.Format.usMoney,
dataIndex: 'rate',
summaryType: 'average'
}, {
id: 'cost',
header: 'Cost',
width: 75,
sortable: false,
groupable: false,
renderer: function(value, metaData, record, rowIdx, colIdx, store, view) {
return Ext.util.Format.usMoney(record.get('estHours') * record.get('rate'));
},
dataIndex: 'cost',
summaryRenderer: Ext.util.Format.usMoney
}]
});
});