@@ -7,20 +7,24 @@ import 'slickgrid/slick.grid';
7
7
import 'slickgrid/slick.dataview' ;
8
8
9
9
// ...then everything else...
10
- import { AfterViewInit , Component , ElementRef , EventEmitter , Inject , Injectable , Input , Output , OnDestroy , OnInit , Optional } from '@angular/core' ;
10
+ import { AfterViewInit , Component , ElementRef , EventEmitter , Inject , Input , Output , OnDestroy , OnInit , Optional } from '@angular/core' ;
11
11
import { TranslateService } from '@ngx-translate/core' ;
12
+
13
+ import { Constants } from '../constants' ;
12
14
import { GlobalGridOptions } from './../global-grid-options' ;
13
15
import { titleCase , unsubscribeAllObservables } from './../services/utilities' ;
14
16
import { executeBackendProcessesCallback , onBackendError } from '../services/backend-utilities' ;
15
17
import {
16
18
AngularGridInstance ,
19
+ BackendServiceApi ,
17
20
BackendServiceOption ,
18
21
Column ,
19
22
ExtensionName ,
20
23
GraphqlResult ,
21
24
GridOption ,
22
25
GridStateChange ,
23
26
GridStateType ,
27
+ Locale ,
24
28
Pagination ,
25
29
} from './../models/index' ;
26
30
import { FilterFactory } from '../filters/filterFactory' ;
@@ -63,7 +67,6 @@ declare var $: any;
63
67
64
68
const slickgridEventPrefix = 'sg' ;
65
69
66
- @Injectable ( )
67
70
@Component ( {
68
71
selector : 'angular-slickgrid' ,
69
72
templateUrl : './angular-slickgrid.component.html' ,
@@ -108,12 +111,15 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
108
111
private _hideHeaderRowAfterPageLoad = false ;
109
112
dataView : any ;
110
113
grid : any ;
111
- gridPaginationOptions : GridOption ;
112
114
gridHeightString : string ;
113
115
gridWidthString : string ;
114
116
groupingDefinition : any = { } ;
115
117
groupItemMetadataProvider : any ;
118
+ backendServiceApi : BackendServiceApi ;
119
+ locales : Locale ;
120
+ paginationOptions : Pagination ;
116
121
showPagination = false ;
122
+ totalItems = 0 ;
117
123
isGridInitialized = false ;
118
124
subscriptions : Subscription [ ] = [ ] ;
119
125
@@ -234,6 +240,9 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
234
240
// make sure the dataset is initialized (if not it will throw an error that it cannot getLength of null)
235
241
this . _dataset = this . _dataset || [ ] ;
236
242
this . gridOptions = this . mergeGridOptions ( this . gridOptions ) ;
243
+ this . paginationOptions = this . gridOptions . pagination ;
244
+ this . locales = this . gridOptions && this . gridOptions . locales || Constants . locales ;
245
+ this . backendServiceApi = this . gridOptions && this . gridOptions . backendServiceApi ;
237
246
this . createBackendApiInternalPostProcessCallback ( this . gridOptions ) ;
238
247
239
248
if ( ! this . customDataView ) {
@@ -564,10 +573,10 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
564
573
try {
565
574
// the processes can be Observables (like HttpClient) or Promises
566
575
if ( process instanceof Promise && process . then ) {
567
- process . then ( ( processResult : GraphqlResult | any ) => executeBackendProcessesCallback ( startTime , processResult , backendApi , this . gridOptions ) ) ;
576
+ process . then ( ( processResult : GraphqlResult | any ) => executeBackendProcessesCallback ( startTime , processResult , backendApi , this . gridOptions . pagination . totalItems ) ) ;
568
577
} else if ( isObservable ( process ) ) {
569
578
process . subscribe (
570
- ( processResult : GraphqlResult | any ) => executeBackendProcessesCallback ( startTime , processResult , backendApi , this . gridOptions ) ,
579
+ ( processResult : GraphqlResult | any ) => executeBackendProcessesCallback ( startTime , processResult , backendApi , this . gridOptions . pagination . totalItems ) ,
571
580
( error : any ) => onBackendError ( error , backendApi )
572
581
) ;
573
582
}
@@ -665,24 +674,25 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
665
674
this . grid . render ( ) ;
666
675
}
667
676
668
- if ( this . gridOptions . backendServiceApi ) {
677
+ if ( this . gridOptions && this . gridOptions . backendServiceApi && this . gridOptions . pagination ) {
669
678
// do we want to show pagination?
670
679
// if we have a backendServiceApi and the enablePagination is undefined, we'll assume that we do want to see it, else get that defined value
671
680
this . showPagination = ( ( this . gridOptions . backendServiceApi && this . gridOptions . enablePagination === undefined ) ? true : this . gridOptions . enablePagination ) || false ;
672
681
673
- // before merging the grid options, make sure that it has the totalItems count
674
- // once we have that, we can merge and pass all these options to the pagination component
675
- if ( ! this . gridOptions . pagination ) {
676
- this . gridOptions . pagination = ( this . gridOptions . pagination ) ? this . gridOptions . pagination : undefined ;
677
- }
678
- if ( this . gridOptions . pagination && totalCount !== undefined ) {
679
- this . gridOptions . pagination . totalItems = totalCount ;
680
- }
681
682
if ( this . gridOptions . presets && this . gridOptions . presets . pagination && this . gridOptions . pagination ) {
682
- this . gridOptions . pagination . pageSize = this . gridOptions . presets . pagination . pageSize ;
683
- this . gridOptions . pagination . pageNumber = this . gridOptions . presets . pagination . pageNumber ;
683
+ this . paginationOptions . pageSize = this . gridOptions . presets . pagination . pageSize ;
684
+ this . paginationOptions . pageNumber = this . gridOptions . presets . pagination . pageNumber ;
684
685
}
685
- this . gridPaginationOptions = this . mergeGridOptions ( this . gridOptions ) ;
686
+
687
+ // when we have a totalCount use it, else we'll take it from the pagination object
688
+ // only update the total items if it's different to avoid refreshing the UI
689
+ const totalRecords = totalCount !== undefined ? totalCount : this . gridOptions . pagination . totalItems ;
690
+ if ( totalRecords !== this . totalItems ) {
691
+ this . totalItems = totalRecords ;
692
+ }
693
+ } else {
694
+ // without backend service, we'll assume the total of items is the dataset size
695
+ this . totalItems = dataset . length ;
686
696
}
687
697
688
698
// resize the grid inside a slight timeout, in case other DOM element changed prior to the resize (like a filter/pagination changed)
0 commit comments