@@ -23,7 +23,7 @@ export class RemotePagingBatchEditingComponent implements OnInit, AfterViewInit,
2323
2424 private _perPage = 10 ;
2525 private _dataLengthSubscriber ;
26- private _recordOnServer = 0 ;
26+ private _recordsOnServer = 0 ;
2727 private _totalPagesOnServer = 0 ;
2828 constructor ( private remoteService : RemotePagingWithBatchEditingService ) {
2929 }
@@ -34,15 +34,15 @@ export class RemotePagingBatchEditingComponent implements OnInit, AfterViewInit,
3434
3535 public set perPage ( val : number ) {
3636 this . _perPage = val ;
37- this . _totalPagesOnServer = Math . floor ( this . _recordOnServer / this . perPage ) ;
37+ this . _totalPagesOnServer = Math . floor ( this . _recordsOnServer / this . perPage ) ;
3838 this . paginate ( 0 ) ;
3939 }
4040
4141 public ngOnInit ( ) {
4242 this . data = this . remoteService . data$ ;
4343 this . _dataLengthSubscriber = this . remoteService . getDataLength ( ) . subscribe ( ( data ) => {
4444 this . totalCount = data ;
45- this . _recordOnServer = data ;
45+ this . _recordsOnServer = data ;
4646 this . _totalPagesOnServer = Math . floor ( this . totalCount / this . perPage ) ;
4747 } ) ;
4848 this . remoteService . getData ( 0 , this . perPage ) . subscribe ( ( ) => {
@@ -107,11 +107,13 @@ export class RemotePagingBatchEditingComponent implements OnInit, AfterViewInit,
107107
108108 public undo ( ) {
109109 this . grid1 . transactions . undo ( ) ;
110+ this . computeTotalCount ( ) ;
110111 this . preventDisplayingEmptyPages ( ) ;
111112 }
112113
113114 public redo ( ) {
114115 this . grid1 . transactions . redo ( ) ;
116+ this . computeTotalCount ( ) ;
115117 this . preventDisplayingEmptyPages ( ) ;
116118 }
117119
@@ -127,7 +129,7 @@ export class RemotePagingBatchEditingComponent implements OnInit, AfterViewInit,
127129 this . remoteService . processBatch ( aggregatedChanges ) . subscribe ( {
128130 next : ( count : number ) => {
129131 this . totalCount = count ;
130- this . _recordOnServer = count ;
132+ this . _recordsOnServer = count ;
131133 console . log ( count )
132134 this . grid1 . transactions . commit ( this . grid1 . data ) ;
133135 this . preventDisplayingEmptyPages ( ) ;
@@ -147,7 +149,7 @@ export class RemotePagingBatchEditingComponent implements OnInit, AfterViewInit,
147149
148150 public discard ( ) {
149151 this . grid1 . transactions . clear ( ) ;
150- this . totalCount = this . _recordOnServer ;
152+ this . totalCount = this . _recordsOnServer ;
151153 this . preventDisplayingEmptyPages ( ) ;
152154 this . dialog . close ( ) ;
153155 }
@@ -169,12 +171,18 @@ export class RemotePagingBatchEditingComponent implements OnInit, AfterViewInit,
169171 }
170172
171173 private preventDisplayingEmptyPages ( ) {
172- this . _totalPagesOnServer = Math . floor ( this . _recordOnServer / this . perPage ) ;
174+ this . _totalPagesOnServer = Math . floor ( this . _recordsOnServer / this . perPage ) ;
175+
176+ const totalPages = Math . floor ( this . totalCount / this . perPage ) ;
173177 if ( this . page > 0 &&
174- ( this . page > this . _totalPagesOnServer ||
175- ( this . page === this . _totalPagesOnServer &&
176- this . _recordOnServer % 10 === 0 ) ) ) {
177- this . paginate ( this . _totalPagesOnServer - 1 ) ;
178+ ( this . page > totalPages ||
179+ ( this . page === totalPages &&
180+ this . totalCount % this . perPage === 0 ) ) ) {
181+ this . paginate ( totalPages - 1 ) ;
178182 }
179183 }
184+
185+ private computeTotalCount ( ) {
186+ this . totalCount = this . _recordsOnServer + this . grid1 . transactions . getAggregatedChanges ( true ) . filter ( rec => rec . type === 'add' ) . length ;
187+ }
180188}
0 commit comments