WeaverTableExt.js
5.52 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
Ext.namespace('Weaver');
Weaver.WeaverTableExt = function(config,tbar) {
//alert(tbar)
var store = new Ext.data.Store({
baseParams : {
TableBaseParas : Ext.util.JSON.encode(config.TableBaseParas)
},
// load using script tags for cross domain, if the data in on the same
// domain as
// this page, an HttpProxy would be better
proxy : new Ext.data.HttpProxy({
method : 'POST',
// url: '/js/extjs/zdp/GridData.jsp'
//url : '/weaver/weaver.secondary.util.SplitPageXmlServletNew'
url : '/weaver/weaver.common.util.taglib.SplitPageXmlServletNew'
}),
// create reader that reads the Topic records
reader : new Ext.data.JsonReader({
root : 'data',
totalProperty : 'totalCount',
id : 'id',
fields : getColumnFields(config)
}),
// turn on remote sorting
remoteSort : true
});
// alert(config.TableBaseParas.sort)
store.setDefaultSort(config.TableBaseParas.sort, config.TableBaseParas.dir);
// the column model has information about grid columns
// dataIndex maps the column to the specific data field in
// the data store
var bbar = new Ext.PagingToolbar({
pageSize : config.TableBaseParas.pageSize,
store : store,
displayInfo : true,
displayMsg : wmsg.grid.gridDisp1 + '{0} - {1}' + wmsg.grid.gridDisp2
+ '{2}' + wmsg.grid.gridDisp3,
emptyMsg : wmsg.grid.noItem
/*
* ,items:[ '-', { pressed: true, enableToggle:true, text:
* wmsg.grid.preview, iconCls: 'btn_details', toggleHandler:
* toggleDetails } ]
*/
});
var columns = config.TableBaseParas.columns;
var sm = new Ext.grid.RowSelectionModel({handleMouseDown: Ext.emptyFn});
// 需要Checkbox
if (config.gridType == "checkbox") {
sm = new Ext.grid.CheckboxSelectionModel({handleMouseDown: Ext.emptyFn});
columns = [sm].concat(columns);
}
// 如果需要行号
if (config.isNeedRowNumber == true) {
columns = [new Ext.grid.RowNumberer()].concat(columns);
}
// by default columns are sortable
// 如果需要操作权限
// if(config.TableBaseParas.operates!=null){
// columns=columns.concat([{id:'operates', header: "操作1", width: 0.3,
// sortable: false, dataIndex: 'operates', column:'operates',hidden:
// false}]);
// }
var gridHeight = config.TableBaseParas.pageSize * config.columnWidth + 60;
var cm = new Ext.grid.ColumnModel(columns);
cm.defaultSortable = true;
// alert(config.TableBaseParas.pageSize*35)
Ext.override(Ext.grid.GridView, {
templates : {
cell : new Ext.Template(
'<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
'<div class="x-grid3-cell-inner x-grid3-col-{id}" {attr}>{value}</div>',
"</td>")
}
});
var grid;
if(tbar=="[]"||tbar==""){
grid = new Ext.grid.GridPanel({
id : config.tableId,
el : config.el,
width : document.getElementById(config.el_temp).offsetWidth,
height : gridHeight,
title : config.title,
store : store,
cm : cm,
trackMouseOver : true,
autoSizeColumns : true,
sm : sm,
stripeRows : true,
loadMask : true,
viewConfig : {
forceFit : true,
emptyText : wmsg.grid.noItem
},
bbar : bbar
});
} else {
gridHeight = gridHeight+20;
grid = new Ext.grid.GridPanel({
id : config.tableId,
el : config.el,
width : document.getElementById(config.el_temp).offsetWidth,
height : gridHeight,
title : config.title,
store : store,
cm : cm,
trackMouseOver : true,
autoSizeColumns : true,
sm : sm,
stripeRows : true,
loadMask : true,
viewConfig : {
forceFit : true,
emptyText : wmsg.grid.noItem
},
tbar : eval(tbar),
bbar : bbar
});
}
// render it
// grid.on('rowmousedown', function(grid, rowIndex, columnIndex, e) {
// infoArea.value=infoArea.value+"rowmousedown cus\n";
// });
// grid.removeListener("rowclick", function(){});
grid.render();
store.load({
params : {
start : 0,
limit : config.TableBaseParas.pageSize
}
});
// trigger the data store load
// grid.removeListener("rowmousedown", sm.handleMouseDown, sm);
document.getElementById(config.el_temp).style.height = gridHeight;
// alert(gridHeight)
// alert(document.getElementById(config.el_temp).style.height);
return {
init : function() {
},
getGridWidth : function() {
return grid.width;
},
setGridWidth : function(newWidth) {
grid.setWidth(newWidth);
},
getGridHeight : function() {
return grid.height;
},
setGridHeight : function(newHeight) {
grid.setHeight(newHeight);
},
firstPage : function() {
bbar.moveFirst();
},
prePage : function() {
if(bbar.items.get(1).disabled==false){
bbar.movePrevious();
}
},
nextPage : function() {
if(bbar.items.get(7).disabled==false){
bbar.moveNext();
}
},
lastPage : function() {
bbar.moveLast();
},
reLoad : function() {
bbar.onClick("refresh");
},
refresh : function() {
bbar.doLoad(bbar.cursor);
},
_xtable_CheckedCheckboxId : function() {
var selections = sm.getSelections();
var selectionIds = "";
for (var i = 0; i < selections.length; i++) {
//alert(selections[i].id);
selectionIds+=selections[i].id+",";
}
return selectionIds;
}
}
function toggleDetails(btn, pressed) {
var view = grid.getView();
view.showPreview = pressed;
view.refresh();
}
function getColumnFields(config) {
var strFields = new Array();
var tableColumns = config.TableBaseParas.columns;
for (var i = 0; i < tableColumns.length; i++)
strFields = strFields.concat(tableColumns[i].column);
// alert(strFields.length)
return strFields;
}
}