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-Scroller'>/**
19 </span> * @class Ext.grid.Scroller
20 * @extends Ext.Component
22 * Docked in an Ext.grid.Panel, controls virtualized scrolling and synchronization
23 * across different sections.
27 Ext.define('Ext.grid.Scroller', {
28 extend: 'Ext.Component',
29 alias: 'widget.gridscroller',
31 cls: Ext.baseCSSPrefix + 'scroller',
36 '<div class="' + Ext.baseCSSPrefix + 'scroller-ct" id="{baseId}_ct">',
37 '<div class="' + Ext.baseCSSPrefix + 'stretcher" id="{baseId}_stretch"></div>',
41 initComponent: function() {
44 cls = Ext.baseCSSPrefix + 'scroller-vertical',
47 me.offsets = {bottom: 0};
48 me.scrollProp = 'scrollTop';
51 if (dock === 'top' || dock === 'bottom') {
52 cls = Ext.baseCSSPrefix + 'scroller-horizontal';
54 me.scrollProp = 'scrollLeft';
59 me[sizeProp] = me.scrollerSize = Ext.getScrollbarSize()[sizeProp];
61 me.cls += (' ' + cls);
63 Ext.applyIf(me.renderSelectors, {
64 stretchEl: '.' + Ext.baseCSSPrefix + 'stretcher',
65 scrollEl: '.' + Ext.baseCSSPrefix + 'scroller-ct'
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]');