4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-grid-PagingScroller'>/**
19 </span> * @class Ext.grid.PagingScroller
20 * @extends Ext.grid.Scroller
24 Ext.define('Ext.grid.PagingScroller', {
25 extend: 'Ext.grid.Scroller',
26 alias: 'widget.paginggridscroller',
29 // '<tpl for="pages">',
30 // '<div class="' + Ext.baseCSSPrefix + 'stretcher" style="width: {width}px;height: {height}px;"></div>',
33 <span id='Ext-grid-PagingScroller-cfg-percentageFromEdge'> /**
34 </span> * @cfg {Number} percentageFromEdge This is a number above 0 and less than 1 which specifies
35 * at what percentage to begin fetching the next page. For example if the pageSize is 100
36 * and the percentageFromEdge is the default of 0.35, the paging scroller will prefetch pages
37 * when scrolling up between records 0 and 34 and when scrolling down between records 65 and 99.
39 percentageFromEdge: 0.35,
41 <span id='Ext-grid-PagingScroller-cfg-scrollToLoadBuffer'> /**
42 </span> * @cfg {Number} scrollToLoadBuffer This is the time in milliseconds to buffer load requests
43 * when scrolling the PagingScrollbar.
45 scrollToLoadBuffer: 200,
54 initComponent: function() {
58 ds.on('guaranteedrange', this.onGuaranteedRange, this);
59 this.callParent(arguments);
62 onGuaranteedRange: function(range, start, end) {
66 // this should never happen
67 if (range.length && me.visibleStart < range[0].index) {
71 ds.loadRecords(range);
77 me.on('afterrender', this.invalidate, this, {single: true});
90 scrollerElDom = this.scrollEl.dom,
91 rowOffset = me.visibleStart - store.guaranteedStart,
92 scrollBy = rowOffset * me.rowHeight,
93 scrollHeight = scrollerElDom.scrollHeight,
94 clientHeight = scrollerElDom.clientHeight,
95 scrollTop = scrollerElDom.scrollTop,
98 // BrowserBug: clientHeight reports 0 in IE9 StrictMode
99 // Instead we are using offsetHeight and hardcoding borders
100 if (Ext.isIE9 && Ext.isStrict) {
101 clientHeight = scrollerElDom.offsetHeight + 2;
104 // This should always be zero or greater than zero but staying
105 // safe and less than 0 we'll scroll to the bottom.
106 useMaximum = (scrollHeight - clientHeight - scrollTop <= 0);
107 this.setViewScrollTop(scrollBy, useMaximum);
110 getPageData : function(){
111 var panel = this.getPanel(),
113 totalCount = store.getTotalCount();
117 currentPage : store.currentPage,
118 pageCount: Math.ceil(totalCount / store.pageSize),
119 fromRecord: ((store.currentPage - 1) * store.pageSize) + 1,
120 toRecord: Math.min(store.currentPage * store.pageSize, totalCount)
124 onElScroll: function(e, t) {
126 panel = me.getPanel(),
128 pageSize = store.pageSize,
129 guaranteedStart = store.guaranteedStart,
130 guaranteedEnd = store.guaranteedEnd,
131 totalCount = store.getTotalCount(),
132 numFromEdge = Math.ceil(me.percentageFromEdge * store.pageSize),
133 position = t.scrollTop,
134 visibleStart = Math.floor(position / me.rowHeight),
135 view = panel.down('tableview'),
137 visibleHeight = viewEl.getHeight(),
138 visibleAhead = Math.ceil(visibleHeight / me.rowHeight),
139 visibleEnd = visibleStart + visibleAhead,
140 prevPage = Math.floor(visibleStart / store.pageSize),
141 nextPage = Math.floor(visibleEnd / store.pageSize) + 2,
142 lastPage = Math.ceil(totalCount / store.pageSize),
143 //requestStart = visibleStart,
144 requestStart = Math.floor(visibleStart / me.snapIncrement) * me.snapIncrement,
145 requestEnd = requestStart + pageSize - 1,
146 activePrefetch = me.activePrefetch;
148 me.visibleStart = visibleStart;
149 me.visibleEnd = visibleEnd;
151 me.syncScroll = true;
152 if (totalCount >= pageSize) {
153 // end of request was past what the total is, grab from the end back a pageSize
154 if (requestEnd > totalCount - 1) {
156 if (store.rangeSatisfied(totalCount - pageSize, totalCount - 1)) {
157 me.syncScroll = true;
159 store.guaranteeRange(totalCount - pageSize, totalCount - 1);
160 // Out of range, need to reset the current data set
161 } else if (visibleStart < guaranteedStart || visibleEnd > guaranteedEnd) {
162 if (store.rangeSatisfied(requestStart, requestEnd)) {
164 store.guaranteeRange(requestStart, requestEnd);
167 me.attemptLoad(requestStart, requestEnd);
169 // dont sync the scroll view immediately, sync after the range has been guaranteed
170 me.syncScroll = false;
171 } else if (activePrefetch && visibleStart < (guaranteedStart + numFromEdge) && prevPage > 0) {
172 me.syncScroll = true;
173 store.prefetchPage(prevPage);
174 } else if (activePrefetch && visibleEnd > (guaranteedEnd - numFromEdge) && nextPage < lastPage) {
175 me.syncScroll = true;
176 store.prefetchPage(nextPage);
185 getSizeCalculation: function() {
186 // Use the direct ownerCt here rather than the scrollerOwner
187 // because we are calculating widths/heights.
188 var owner = this.ownerGrid,
189 view = owner.getView(),
196 if (!this.rowHeight) {
197 this.rowHeight = view.el.down(view.getItemSelector()).getHeight(false, true);
200 // If the Store is *locally* filtered, use the filtered count from getCount.
201 height = store[(!store.remoteFilter && store.isFiltered()) ? 'getCount' : 'getTotalCount']() * this.rowHeight;
215 attemptLoad: function(start, end) {
218 me.loadTask = Ext.create('Ext.util.DelayedTask', me.doAttemptLoad, me, []);
220 me.loadTask.delay(me.scrollToLoadBuffer, me.doAttemptLoad, me, [start, end]);
223 cancelLoad: function() {
225 this.loadTask.cancel();
229 doAttemptLoad: function(start, end) {
230 var store = this.getPanel().store;
231 store.guaranteeRange(start, end);
234 setViewScrollTop: function(scrollTop, useMax) {
235 var owner = this.getPanel(),
236 items = owner.query('tableview'),
243 scrollerElDom = this.el.dom;
245 owner.virtualScrollTop = scrollTop;
247 center = items[1] || items[0];
248 centerEl = center.el.dom;
250 maxScrollTop = ((owner.store.pageSize * this.rowHeight) - centerEl.clientHeight);
251 calcScrollTop = (scrollTop % ((owner.store.pageSize * this.rowHeight) + 1));
253 calcScrollTop = maxScrollTop;
255 if (calcScrollTop > maxScrollTop) {
256 //Ext.Error.raise("Calculated scrollTop was larger than maxScrollTop");
258 // calcScrollTop = maxScrollTop;
260 for (; i < len; i++) {
261 items[i].el.dom.scrollTop = calcScrollTop;