X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/0494b8d9b9bb03ab6c22b34dae81261e3cd7e3e6..7a654f8d43fdb43d78b63d90528bed6e86b608cc:/src/grid/feature/Chunking.js diff --git a/src/grid/feature/Chunking.js b/src/grid/feature/Chunking.js new file mode 100644 index 00000000..831d0542 --- /dev/null +++ b/src/grid/feature/Chunking.js @@ -0,0 +1,82 @@ +/** + * @class Ext.grid.feature.Chunking + * @extends Ext.grid.feature.Feature + */ +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() { + var grid = this.view.up('gridpanel'), + scroller = grid.down('gridscroller[dock=right]'); + scroller.el.on('scroll', this.onBodyScroll, this, {buffer: 300}); + //this.view.on('bodyscroll', 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, orig) { + var o = { + fullWidth: orig.fullWidth, + chunks: [] + }, + //headerCt = this.view.headerCt, + //colums = headerCt.getColumnsForTpl(), + recordCount = orig.rows.length, + start = 0, + i = 0, + visibleChunk = this.visibleChunk, + chunk, + rows, + chunkLength; + + for (; start < recordCount; start+=this.chunkSize, i++) { + if (start+this.chunkSize > recordCount) { + chunkLength = recordCount - start; + } else { + chunkLength = this.chunkSize; + } + + if (i >= visibleChunk - 1 && i <= visibleChunk + 1) { + rows = orig.rows.slice(start, start+this.chunkSize); + } else { + rows = []; + } + o.chunks.push({ + rows: rows, + fullWidth: fullWidth, + chunkHeight: chunkLength * this.rowHeight + }); + } + + + return o; + }, + + getTableFragments: function() { + return { + openTableWrap: function() { + return '
'; + }, + closeTableWrap: function() { + return '
'; + } + }; + } +});