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-Scroller'>/**
19 </span> * Docked in an Ext.grid.Panel, controls virtualized scrolling and synchronization
20 * across different sections.
22 Ext.define('Ext.grid.Scroller', {
23 extend: 'Ext.Component',
24 alias: 'widget.gridscroller',
26 baseCls: Ext.baseCSSPrefix + 'scroller',
31 '<div class="' + Ext.baseCSSPrefix + 'scroller-ct" id="{baseId}_ct">',
32 '<div class="' + Ext.baseCSSPrefix + 'stretcher" id="{baseId}_stretch"></div>',
36 initComponent: function() {
39 cls = Ext.baseCSSPrefix + 'scroller-vertical';
41 me.offsets = {bottom: 0};
42 me.scrollProp = 'scrollTop';
44 me.sizeProp = 'width';
46 if (dock === 'top' || dock === 'bottom') {
47 cls = Ext.baseCSSPrefix + 'scroller-horizontal';
48 me.sizeProp = 'height';
49 me.scrollProp = 'scrollLeft';
54 me.cls += (' ' + cls);
56 Ext.applyIf(me.renderSelectors, {
57 stretchEl: '.' + Ext.baseCSSPrefix + 'stretcher',
58 scrollEl: '.' + Ext.baseCSSPrefix + 'scroller-ct'
63 ensureDimension: function(){
65 sizeProp = me.sizeProp;
67 me[sizeProp] = me.scrollerSize = Ext.getScrollbarSize()[sizeProp];
70 initRenderData: function () {
72 ret = me.callParent(arguments) || {};
79 afterRender: function() {
83 me.mon(me.scrollEl, 'scroll', me.onElScroll, me);
84 Ext.cache[me.el.id].skipGarbageCollection = true;
87 onAdded: function(container) {
88 // Capture the controlling grid Panel so that we can use it even when we are undocked, and don't have an ownerCt
89 this.ownerGrid = container;
90 this.callParent(arguments);
93 getSizeCalculation: function() {
95 owner = me.getPanel(),
101 // TODO: Must gravitate to a single region..
102 // Horizontal scrolling only scrolls virtualized region
103 var items = owner.query('tableview'),
104 center = items[1] || items[0];
109 // center is not guaranteed to have content, such as when there
110 // are zero rows in the grid/tree. We read the width from the
112 width = center.headerCt.getFullWidth();
114 if (Ext.isIEQuirks) {
118 view = owner.down('tableview:not([lockableInjected])');
119 if (!view || !view.el) {
122 tbl = view.el.child('table', true);
127 // needs to also account for header and scroller (if still in picture)
128 // should calculate from headerCt.
129 height = tbl.offsetHeight;
143 invalidate: function(firstPass) {
145 stretchEl = me.stretchEl;
147 if (!stretchEl || !me.ownerCt) {
151 var size = me.getSizeCalculation(),
152 scrollEl = me.scrollEl,
153 elDom = scrollEl.dom,
154 reservedSpace = me.reservedSpace,
159 stretchEl.setSize(size);
161 size = me.el.getSize(true);
165 size.height -= reservedSpace;
168 size.width -= reservedSpace;
169 size.height += extra;
173 scrollEl.setSize(size);
174 elDom.style[pos] = (-extra) + 'px';
177 // This makes the scroller enabled, when initially rendering.
178 elDom.scrollTop = elDom.scrollTop;
182 afterComponentLayout: function() {
183 this.callParent(arguments);
187 restoreScrollPos: function () {
190 elDom = el && el.dom;
192 if (me._scrollPos !== null && elDom) {
193 elDom[me.scrollProp] = me._scrollPos;
194 me._scrollPos = null;
198 setReservedSpace: function (reservedSpace) {
200 if (me.reservedSpace !== reservedSpace) {
201 me.reservedSpace = reservedSpace;
206 saveScrollPos: function () {
209 elDom = el && el.dom;
211 me._scrollPos = elDom ? elDom[me.scrollProp] : null;
214 <span id='Ext-grid-Scroller-method-setScrollTop'> /**
215 </span> * Sets the scrollTop and constrains the value between 0 and max.
216 * @param {Number} scrollTop
217 * @return {Number} The resulting scrollTop value after being constrained
219 setScrollTop: function(scrollTop) {
220 var el = this.scrollEl,
221 elDom = el && el.dom;
224 return elDom.scrollTop = Ext.Number.constrain(scrollTop, 0, elDom.scrollHeight - elDom.clientHeight);
228 <span id='Ext-grid-Scroller-method-setScrollLeft'> /**
229 </span> * Sets the scrollLeft and constrains the value between 0 and max.
230 * @param {Number} scrollLeft
231 * @return {Number} The resulting scrollLeft value after being constrained
233 setScrollLeft: function(scrollLeft) {
234 var el = this.scrollEl,
235 elDom = el && el.dom;
238 return elDom.scrollLeft = Ext.Number.constrain(scrollLeft, 0, elDom.scrollWidth - elDom.clientWidth);
242 <span id='Ext-grid-Scroller-method-scrollByDeltaY'> /**
243 </span> * Scroll by deltaY
244 * @param {Number} delta
245 * @return {Number} The resulting scrollTop value
247 scrollByDeltaY: function(delta) {
248 var el = this.scrollEl,
249 elDom = el && el.dom;
252 return this.setScrollTop(elDom.scrollTop + delta);
256 <span id='Ext-grid-Scroller-method-scrollByDeltaX'> /**
257 </span> * Scroll by deltaX
258 * @param {Number} delta
259 * @return {Number} The resulting scrollLeft value
261 scrollByDeltaX: function(delta) {
262 var el = this.scrollEl,
263 elDom = el && el.dom;
266 return this.setScrollLeft(elDom.scrollLeft + delta);
271 <span id='Ext-grid-Scroller-method-scrollToTop'> /**
272 </span> * Scroll to the top.
274 scrollToTop : function(){
275 this.setScrollTop(0);
278 // synchronize the scroller with the bound gridviews
279 onElScroll: function(event, target) {
280 this.fireEvent('bodyscroll', event, target);
283 getPanel: function() {
286 me.panel = this.up('[scrollerOwner]');