This repository was archived by the owner on Sep 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_grids.js
More file actions
69 lines (57 loc) · 1.89 KB
/
custom_grids.js
File metadata and controls
69 lines (57 loc) · 1.89 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
/*globals Ext, SWorks */
/*jslint glovar: true, undef: true, nomen: true */
Ext.override(Ext.grid.GridView, {
// By default it scrolls to the top
onLoad: Ext.emptyFn
});
SWorks.CustomGrid = Ext.extend(Ext.grid.GridPanel, {
autoSizeColumns: true,
minColumnWidth: 5,
initComponent: function() {
this.sm = new Ext.grid.RowSelectionModel({singleSelect:true});
SWorks.CustomGrid.superclass.initComponent.call(this);
this.colModel.defaultSortable = true;
var saver = new SWorks.GridScrollSaver().init(this);
},
loadMask: { removeMask: true },
getView: function() {
if(!this.view) {
if(this.store.groupBy) {
this.view = new Ext.grid.GroupingView(Ext.apply({
forceFit:true,
enableNoGroups: true,
hideGroupedColumn: true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}, this.viewConfig));
} else {
this.view = new Ext.grid.GridView(Ext.apply({
forceFit:true
}, this.viewConfig));
}
}
return this.view;
}
});
SWorks.GridScrollSaver = function() {};
SWorks.GridScrollSaver.prototype = {
init: function(grid) {
// Called in the scope of the grid
var returnToSavedPosition = function() {
if(this.savedScrollPos && this.view &&
this.ownerCt.layout.activeItem == this) {
this.view.scroller.scrollTo('top', this.savedScrollPos);
}
};
grid.on('bodyscroll', function(y, x) { grid.savedScrollPos = x; });
grid.on('show', returnToSavedPosition, grid);
grid.on('activate', returnToSavedPosition, grid);
grid.on('render', function() {
grid.view.on('refresh', returnToSavedPosition, grid);
if(grid.ownerCt) {
grid.ownerCt.on('afterlayout', returnToSavedPosition, grid);
} else {
grid.on('afterlayout', returnToSavedPosition, grid);
}
});
}
};