4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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
22 Ext.define('Ext.grid.PagingScroller', {
23 extend: 'Ext.grid.Scroller',
24 alias: 'widget.paginggridscroller',
27 // '<tpl for="pages">',
28 // '<div class="' + Ext.baseCSSPrefix + 'stretcher" style="width: {width}px;height: {height}px;"></div>',
31 <span id='Ext-grid-PagingScroller-cfg-percentageFromEdge'> /**
32 </span> * @cfg {Number} percentageFromEdge This is a number above 0 and less than 1 which specifies
33 * at what percentage to begin fetching the next page. For example if the pageSize is 100
34 * and the percentageFromEdge is the default of 0.35, the paging scroller will prefetch pages
35 * when scrolling up between records 0 and 34 and when scrolling down between records 65 and 99.
37 percentageFromEdge: 0.35,
39 <span id='Ext-grid-PagingScroller-cfg-scrollToLoadBuffer'> /**
40 </span> * @cfg {Number} scrollToLoadBuffer This is the time in milliseconds to buffer load requests
41 * when scrolling the PagingScrollbar.
43 scrollToLoadBuffer: 200,
52 initComponent: function() {
56 ds.on('guaranteedrange', me.onGuaranteedRange, me);
57 me.callParent(arguments);
60 onGuaranteedRange: function(range, start, end) {
64 // this should never happen
65 if (range.length && me.visibleStart < range[0].index) {
69 ds.loadRecords(range);
75 me.on('afterrender', me.invalidate, me, {single: true});
80 // only sync if there is a paging scrollbar element and it has a scroll height (meaning it's currently in the DOM)
81 if (me.scrollEl && me.scrollEl.dom && me.scrollEl.dom.scrollHeight) {
91 scrollerElDom = this.scrollEl.dom,
92 rowOffset = me.visibleStart - store.guaranteedStart,
93 scrollBy = rowOffset * me.rowHeight,
94 scrollHeight = scrollerElDom.scrollHeight,
95 clientHeight = scrollerElDom.clientHeight,
96 scrollTop = scrollerElDom.scrollTop,
100 // BrowserBug: clientHeight reports 0 in IE9 StrictMode
101 // Instead we are using offsetHeight and hardcoding borders
102 if (Ext.isIE9 && Ext.isStrict) {
103 clientHeight = scrollerElDom.offsetHeight + 2;
106 // This should always be zero or greater than zero but staying
107 // safe and less than 0 we'll scroll to the bottom.
108 useMaximum = (scrollHeight - clientHeight - scrollTop <= 0);
109 this.setViewScrollTop(scrollBy, useMaximum);
112 getPageData : function(){
113 var panel = this.getPanel(),
115 totalCount = store.getTotalCount();
119 currentPage : store.currentPage,
120 pageCount: Math.ceil(totalCount / store.pageSize),
121 fromRecord: ((store.currentPage - 1) * store.pageSize) + 1,
122 toRecord: Math.min(store.currentPage * store.pageSize, totalCount)
126 onElScroll: function(e, t) {
128 panel = me.getPanel(),
130 pageSize = store.pageSize,
131 guaranteedStart = store.guaranteedStart,
132 guaranteedEnd = store.guaranteedEnd,
133 totalCount = store.getTotalCount(),
134 numFromEdge = Math.ceil(me.percentageFromEdge * pageSize),
135 position = t.scrollTop,
136 visibleStart = Math.floor(position / me.rowHeight),
137 view = panel.down('tableview'),
139 visibleHeight = viewEl.getHeight(),
140 visibleAhead = Math.ceil(visibleHeight / me.rowHeight),
141 visibleEnd = visibleStart + visibleAhead,
142 prevPage = Math.floor(visibleStart / pageSize),
143 nextPage = Math.floor(visibleEnd / pageSize) + 2,
144 lastPage = Math.ceil(totalCount / pageSize),
145 snap = me.snapIncrement,
146 requestStart = Math.floor(visibleStart / snap) * snap,
147 requestEnd = requestStart + pageSize - 1,
148 activePrefetch = me.activePrefetch;
150 me.visibleStart = visibleStart;
151 me.visibleEnd = visibleEnd;
154 me.syncScroll = true;
155 if (totalCount >= pageSize) {
156 // end of request was past what the total is, grab from the end back a pageSize
157 if (requestEnd > totalCount - 1) {
159 if (store.rangeSatisfied(totalCount - pageSize, totalCount - 1)) {
160 me.syncScroll = true;
162 store.guaranteeRange(totalCount - pageSize, totalCount - 1);
163 // Out of range, need to reset the current data set
164 } else if (visibleStart <= guaranteedStart || visibleEnd > guaranteedEnd) {
165 if (visibleStart <= guaranteedStart) {
167 requestStart -= snap;
170 if (requestStart < 0) {
172 requestEnd = pageSize;
175 if (store.rangeSatisfied(requestStart, requestEnd)) {
177 store.guaranteeRange(requestStart, requestEnd);
180 me.attemptLoad(requestStart, requestEnd);
182 // dont sync the scroll view immediately, sync after the range has been guaranteed
183 me.syncScroll = false;
184 } else if (activePrefetch && visibleStart < (guaranteedStart + numFromEdge) && prevPage > 0) {
185 me.syncScroll = true;
186 store.prefetchPage(prevPage);
187 } else if (activePrefetch && visibleEnd > (guaranteedEnd - numFromEdge) && nextPage < lastPage) {
188 me.syncScroll = true;
189 store.prefetchPage(nextPage);
198 getSizeCalculation: function() {
199 // Use the direct ownerCt here rather than the scrollerOwner
200 // because we are calculating widths/heights.
202 owner = me.ownerGrid,
203 view = owner.getView(),
211 me.rowHeight = view.el.down(view.getItemSelector()).getHeight(false, true);
214 // If the Store is *locally* filtered, use the filtered count from getCount.
215 height = store[(!store.remoteFilter && store.isFiltered()) ? 'getCount' : 'getTotalCount']() * me.rowHeight;
229 attemptLoad: function(start, end) {
232 me.loadTask = Ext.create('Ext.util.DelayedTask', me.doAttemptLoad, me, []);
234 me.loadTask.delay(me.scrollToLoadBuffer, me.doAttemptLoad, me, [start, end]);
237 cancelLoad: function() {
239 this.loadTask.cancel();
243 doAttemptLoad: function(start, end) {
244 var store = this.getPanel().store;
245 store.guaranteeRange(start, end);
248 setViewScrollTop: function(scrollTop, useMax) {
250 owner = me.getPanel(),
251 items = owner.query('tableview'),
258 scrollerElDom = me.el.dom;
260 owner.virtualScrollTop = scrollTop;
262 center = items[1] || items[0];
263 centerEl = center.el.dom;
265 maxScrollTop = ((owner.store.pageSize * me.rowHeight) - centerEl.clientHeight);
266 calcScrollTop = (scrollTop % ((owner.store.pageSize * me.rowHeight) + 1));
268 calcScrollTop = maxScrollTop;
270 if (calcScrollTop > maxScrollTop) {
271 //Ext.Error.raise("Calculated scrollTop was larger than maxScrollTop");
273 // calcScrollTop = maxScrollTop;
275 for (; i < len; i++) {
276 items[i].el.dom.scrollTop = calcScrollTop;