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',
34 renderTpl: ['<div class="' + Ext.baseCSSPrefix + 'stretcher"></div>'],
36 initComponent: function() {
39 cls = Ext.baseCSSPrefix + 'scroller-vertical',
41 // Subtracting 2px would give us a perfect fit of the scroller
42 // however, some browsers wont allow us to scroll content thats not
43 // visible, therefore we use 1px.
44 // Note: This 1px offset matches code in Ext.grid.ColumnLayout when
45 // reserving room for the scrollbar
46 scrollbarWidth = Ext.getScrollBarWidth() + (Ext.isIE ? 1 : -1);
48 me.offsets = {bottom: 0};
50 if (dock === 'top' || dock === 'bottom') {
51 cls = Ext.baseCSSPrefix + 'scroller-horizontal';
54 me[sizeProp] = scrollbarWidth;
56 me.cls += (' ' + cls);
58 Ext.applyIf(me.renderSelectors, {
59 stretchEl: '.' + Ext.baseCSSPrefix + 'stretcher'
65 afterRender: function() {
68 me.ownerCt.on('afterlayout', me.onOwnerAfterLayout, me);
69 me.mon(me.el, 'scroll', me.onElScroll, me);
70 Ext.cache[me.el.id].skipGarbageCollection = true;
73 getSizeCalculation: function() {
74 var owner = this.getPanel(),
81 if (dock === 'top' || dock === 'bottom') {
82 // TODO: Must gravitate to a single region..
83 // Horizontal scrolling only scrolls virtualized region
84 var items = owner.query('tableview'),
85 center = items[1] || items[0];
90 // center is not guaranteed to have content, such as when there
91 // are zero rows in the grid/tree. We read the width from the
93 width = center.headerCt.getFullWidth();
98 // Account for the 1px removed in Scroller.
101 view = owner.down('tableview:not([lockableInjected])');
110 // needs to also account for header and scroller (if still in picture)
111 // should calculate from headerCt.
112 height = tbl.dom.scrollHeight;
126 invalidate: function(firstPass) {
127 if (!this.stretchEl || !this.ownerCt) {
130 var size = this.getSizeCalculation(),
133 this.stretchEl.setSize(size);
136 // This makes the scroller enabled, when initially rendering.
137 elDom.scrollTop = elDom.scrollTop;
141 onOwnerAfterLayout: function(owner, layout) {
145 <span id='Ext-grid-Scroller-method-setScrollTop'> /**
146 </span> * Sets the scrollTop and constrains the value between 0 and max.
147 * @param {Number} scrollTop
148 * @return {Number} The resulting scrollTop value after being constrained
150 setScrollTop: function(scrollTop) {
152 var elDom = this.el.dom;
153 return elDom.scrollTop = Ext.Number.constrain(scrollTop, 0, elDom.scrollHeight - elDom.clientHeight);
157 <span id='Ext-grid-Scroller-method-setScrollLeft'> /**
158 </span> * Sets the scrollLeft and constrains the value between 0 and max.
159 * @param {Number} scrollLeft
160 * @return {Number} The resulting scrollLeft value after being constrained
162 setScrollLeft: function(scrollLeft) {
164 var elDom = this.el.dom;
165 return elDom.scrollLeft = Ext.Number.constrain(scrollLeft, 0, elDom.scrollWidth - elDom.clientWidth);
169 <span id='Ext-grid-Scroller-method-scrollByDeltaY'> /**
170 </span> * Scroll by deltaY
171 * @param {Number} delta
172 * @return {Number} The resulting scrollTop value
174 scrollByDeltaY: function(delta) {
176 var elDom = this.el.dom;
177 return this.setScrollTop(elDom.scrollTop + delta);
181 <span id='Ext-grid-Scroller-method-scrollByDeltaX'> /**
182 </span> * Scroll by deltaX
183 * @param {Number} delta
184 * @return {Number} The resulting scrollLeft value
186 scrollByDeltaX: function(delta) {
188 var elDom = this.el.dom;
189 return this.setScrollLeft(elDom.scrollLeft + delta);
194 <span id='Ext-grid-Scroller-method-scrollToTop'> /**
195 </span> * Scroll to the top.
197 scrollToTop : function(){
198 this.setScrollTop(0);
201 // synchronize the scroller with the bound gridviews
202 onElScroll: function(event, target) {
203 this.fireEvent('bodyscroll', event, target);
206 getPanel: function() {
209 me.panel = this.up('[scrollerOwner]');