@@ -17,6 +17,8 @@ Ext.define('Connector.view.Grid', {
1717
1818 headerHeight : 160 ,
1919
20+ paging : true ,
21+
2022 constructor : function ( config ) {
2123 this . callParent ( [ config ] ) ;
2224 this . addEvents ( 'applyfilter' , 'removefilter' , 'measureselected' ) ;
@@ -123,6 +125,92 @@ Ext.define('Connector.view.Grid', {
123125 } ) ;
124126 } ,
125127
128+ _createFooter : function ( ) {
129+
130+ return Ext . create ( 'Ext.container.Container' , {
131+ height : this . headerHeight ,
132+ ui : 'custom' ,
133+ margin : '10 0 0 15' ,
134+ id : 'grid-paging-footer' ,
135+ layout : {
136+ type : 'hbox' ,
137+ align : 'center'
138+ } ,
139+ items : [ {
140+ // This allows for the following items to be centered
141+ xtype : 'box' ,
142+ flex : 1 ,
143+ autoEl : {
144+ tag : 'div'
145+ }
146+ } , {
147+ xtype : 'button' ,
148+ text : '<<' ,
149+ margin : '0 15 0 0' ,
150+ handler : this . requestFirstPage ,
151+ scope : this
152+ } , {
153+ xtype : 'button' ,
154+ text : '<' ,
155+ margin : '0 15 0 0' ,
156+ handler : this . requestPreviousPage ,
157+ scope : this
158+ } , {
159+ xtype : 'textfield' ,
160+ id : 'grid-page-number' ,
161+ hideLabel : true ,
162+ width : 30 ,
163+ value : 1 ,
164+ enableKeyEvents : true ,
165+ listeners : {
166+ specialkey : this . requestPage
167+ }
168+ } , {
169+ id : 'grid-page-total' ,
170+ xtype : 'label' ,
171+ text : 'of ' + Math . ceil ( this . getGrid ( ) . getStore ( ) . totalCount / this . getGrid ( ) . getStore ( ) . pageSize ) ,
172+ margin : '5 10 0 5'
173+
174+ } , {
175+ xtype : 'button' ,
176+ text : '>' ,
177+ margin : '0 15 0 0' ,
178+ handler : this . requestNextPage ,
179+ scope : this
180+ } , {
181+ xtype : 'button' ,
182+ text : '>>' ,
183+ margin : '0 15 0 0' ,
184+ handler : this . requestLastPage ,
185+ scope : this
186+ } , {
187+ // This allows for the following items to be centered
188+ xtype : 'box' ,
189+ flex : 1 ,
190+ autoEl : {
191+ tag : 'div'
192+ }
193+ } ]
194+ } ) ;
195+ } ,
196+
197+ _updateFooter : function ( ) {
198+ if ( this . footer ) {
199+
200+ var totalPagesEl = this . footer . getComponent ( 'grid-page-total' ) ;
201+ var totalPages = Math . ceil ( this . getGrid ( ) . getStore ( ) . totalCount / this . getGrid ( ) . getStore ( ) . pageSize ) ;
202+ if ( totalPagesEl )
203+ totalPagesEl . setText ( "of " + totalPages ) ;
204+
205+ var currentPageEl = this . footer . getComponent ( 'grid-page-number' ) ;
206+ if ( currentPageEl && parseInt ( currentPageEl . getValue ( ) ) > totalPages ) {
207+ this . requestFirstPage ( )
208+ }
209+
210+ this . updatePageNumber ( ) ;
211+ }
212+ } ,
213+
126214 _showOverlay : function ( ) {
127215 if ( ! this . NO_SHOW ) {
128216
@@ -227,10 +315,14 @@ Ext.define('Connector.view.Grid', {
227315
228316 if ( prevGridId != null && prevGridId != newGrid . getId ( ) ) {
229317 this . remove ( prevGridId , true ) ;
318+ if ( this . paging && this . footer )
319+ this . remove ( this . footer , true ) ;
230320 this . _hideOverlay ( ) ;
231321 }
232322
233323 this . add ( newGrid ) ;
324+ if ( this . paging )
325+ this . footer = this . add ( this . _createFooter ( ) ) ;
234326
235327 } , this , { single : true } ) ;
236328 } ,
@@ -408,6 +500,7 @@ Ext.define('Connector.view.Grid', {
408500 columns : model . get ( 'columnSet' ) ,
409501 filterArray : model . getFilterArray ( true ) ,
410502 maxRows : maxRows ,
503+ pageSize : maxRows ,
411504 remoteSort : true
412505 } ;
413506
@@ -437,9 +530,12 @@ Ext.define('Connector.view.Grid', {
437530 this . fireEvent ( 'hideload' , this ) ;
438531 }
439532
440- if ( rowCount >= maxRows ) {
533+ if ( rowCount >= maxRows && ! this . paging ) {
441534 this . showLimitMessage ( maxRows ) ;
442535 }
536+
537+ this . _updateFooter ( ) ;
538+
443539 } , this ) ;
444540
445541 return store ;
@@ -449,7 +545,11 @@ Ext.define('Connector.view.Grid', {
449545
450546 var box = this . getBox ( ) ;
451547 var width = box . width - 27 ;
452- var height = box . height - this . headerHeight + 93 ;
548+ var height ;
549+ if ( this . paging )
550+ height = box . height - this . headerHeight + 43 ;
551+ else
552+ height = box . height - this . headerHeight + 93 ;
453553
454554 return {
455555 width : width ,
@@ -672,6 +772,61 @@ Ext.define('Connector.view.Grid', {
672772 }
673773 } ,
674774
775+ updatePageNumber : function ( ) {
776+ var store = this . getGrid ( ) . getStore ( ) ;
777+ if ( this . footer ) {
778+ var page = this . footer . getComponent ( 'grid-page-number' ) ;
779+ if ( page )
780+ {
781+ page . setValue ( store . currentPage ) ;
782+ }
783+ }
784+ } ,
785+
786+ requestFirstPage : function ( ) {
787+ this . getGrid ( ) . getStore ( ) . loadPage ( 1 ) ;
788+ this . updatePageNumber ( ) ;
789+ } ,
790+
791+ requestPreviousPage : function ( ) {
792+ var store = this . getGrid ( ) . getStore ( ) ;
793+ if ( store . currentPage > 1 )
794+ {
795+ store . previousPage ( ) ;
796+ this . updatePageNumber ( ) ;
797+ }
798+ } ,
799+
800+ requestNextPage : function ( ) {
801+ var store = this . getGrid ( ) . getStore ( ) ;
802+ if ( store . currentPage < Math . ceil ( store . totalCount / store . pageSize ) )
803+ {
804+ store . nextPage ( ) ;
805+ this . updatePageNumber ( ) ;
806+ }
807+ } ,
808+
809+ requestLastPage : function ( ) {
810+ var store = this . getGrid ( ) . getStore ( ) ;
811+ store . loadPage ( Math . ceil ( store . totalCount / store . pageSize ) ) ;
812+ this . updatePageNumber ( ) ;
813+ } ,
814+
815+ requestPage : function ( f , e ) {
816+ if ( e . getKey ( ) == e . ENTER )
817+ {
818+ var main = this . getBubbleParent ( ) . getBubbleParent ( ) ;
819+ var store = main . getGrid ( ) . getStore ( ) ;
820+
821+ var pageNo = parseInt ( this . getValue ( ) ) ;
822+ if ( pageNo <= Math . ceil ( store . totalCount / store . pageSize ) && pageNo > 0 )
823+ {
824+ store . loadPage ( pageNo ) ;
825+ main . updatePageNumber ( ) ;
826+ }
827+ }
828+ } ,
829+
675830 showLimitMessage : function ( max ) {
676831
677832 var msg = 'The app only shows up ' + max + ' rows. Export to see all data.' ;
0 commit comments