Chunking.html
2.98 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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-grid-feature-Chunking'>/**
</span> *
*/
Ext.define('Ext.grid.feature.Chunking', {
extend: 'Ext.grid.feature.Feature',
alias: 'feature.chunking',
chunkSize: 20,
rowHeight: Ext.isIE ? 27 : 26,
visibleChunk: 0,
hasFeatureEvent: false,
attachEvents: function() {
this.view.el.on('scroll', this.onBodyScroll, this, {buffer: 300});
},
onBodyScroll: function(e, t) {
var view = this.view,
top = t.scrollTop,
nextChunk = Math.floor(top / this.rowHeight / this.chunkSize);
if (nextChunk !== this.visibleChunk) {
this.visibleChunk = nextChunk;
view.refresh();
view.el.dom.scrollTop = top;
//BrowserBug: IE6,7,8 quirks mode takes setting scrollTop 2x.
view.el.dom.scrollTop = top;
}
},
collectData: function(records, preppedRecords, startIndex, fullWidth, o) {
//headerCt = this.view.headerCt,
//colums = headerCt.getColumnsForTpl(),
var me = this,
recordCount = o.rows.length,
start = 0,
i = 0,
visibleChunk = me.visibleChunk,
rows,
chunkLength,
origRows = o.rows;
delete o.rows;
o.chunks = [];
for (; start < recordCount; start += me.chunkSize, i++) {
if (start + me.chunkSize > recordCount) {
chunkLength = recordCount - start;
} else {
chunkLength = me.chunkSize;
}
if (i >= visibleChunk - 1 && i <= visibleChunk + 1) {
rows = origRows.slice(start, start + me.chunkSize);
} else {
rows = [];
}
o.chunks.push({
rows: rows,
fullWidth: fullWidth,
chunkHeight: chunkLength * me.rowHeight
});
}
return o;
},
getTableFragments: function() {
return {
openTableWrap: function() {
return '<tpl for="chunks"><div class="' + Ext.baseCSSPrefix + 'grid-chunk" style="height: {chunkHeight}px;">';
},
closeTableWrap: function() {
return '</div></tpl>';
}
};
}
});
</pre>
</body>
</html>