@@ -7,20 +7,24 @@ import 'slickgrid/slick.grid';
77import 'slickgrid/slick.dataview' ;
88
99// ...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' ;
1111import { TranslateService } from '@ngx-translate/core' ;
12+
13+ import { Constants } from '../constants' ;
1214import { GlobalGridOptions } from './../global-grid-options' ;
1315import { titleCase , unsubscribeAllObservables } from './../services/utilities' ;
1416import { executeBackendProcessesCallback , onBackendError } from '../services/backend-utilities' ;
1517import {
1618 AngularGridInstance ,
19+ BackendServiceApi ,
1720 BackendServiceOption ,
1821 Column ,
1922 ExtensionName ,
2023 GraphqlResult ,
2124 GridOption ,
2225 GridStateChange ,
2326 GridStateType ,
27+ Locale ,
2428 Pagination ,
2529} from './../models/index' ;
2630import { FilterFactory } from '../filters/filterFactory' ;
@@ -63,7 +67,6 @@ declare var $: any;
6367
6468const slickgridEventPrefix = 'sg' ;
6569
66- @Injectable ( )
6770@Component ( {
6871 selector : 'angular-slickgrid' ,
6972 templateUrl : './angular-slickgrid.component.html' ,
@@ -108,12 +111,15 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
108111 private _hideHeaderRowAfterPageLoad = false ;
109112 dataView : any ;
110113 grid : any ;
111- gridPaginationOptions : GridOption ;
112114 gridHeightString : string ;
113115 gridWidthString : string ;
114116 groupingDefinition : any = { } ;
115117 groupItemMetadataProvider : any ;
118+ backendServiceApi : BackendServiceApi ;
119+ locales : Locale ;
120+ paginationOptions : Pagination ;
116121 showPagination = false ;
122+ totalItems = 0 ;
117123 isGridInitialized = false ;
118124 subscriptions : Subscription [ ] = [ ] ;
119125
@@ -234,6 +240,9 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
234240 // make sure the dataset is initialized (if not it will throw an error that it cannot getLength of null)
235241 this . _dataset = this . _dataset || [ ] ;
236242 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 ;
237246 this . createBackendApiInternalPostProcessCallback ( this . gridOptions ) ;
238247
239248 if ( ! this . customDataView ) {
@@ -564,10 +573,10 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
564573 try {
565574 // the processes can be Observables (like HttpClient) or Promises
566575 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 ) ) ;
568577 } else if ( isObservable ( process ) ) {
569578 process . subscribe (
570- ( processResult : GraphqlResult | any ) => executeBackendProcessesCallback ( startTime , processResult , backendApi , this . gridOptions ) ,
579+ ( processResult : GraphqlResult | any ) => executeBackendProcessesCallback ( startTime , processResult , backendApi , this . gridOptions . pagination . totalItems ) ,
571580 ( error : any ) => onBackendError ( error , backendApi )
572581 ) ;
573582 }
@@ -665,24 +674,25 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
665674 this . grid . render ( ) ;
666675 }
667676
668- if ( this . gridOptions . backendServiceApi ) {
677+ if ( this . gridOptions && this . gridOptions . backendServiceApi && this . gridOptions . pagination ) {
669678 // do we want to show pagination?
670679 // 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
671680 this . showPagination = ( ( this . gridOptions . backendServiceApi && this . gridOptions . enablePagination === undefined ) ? true : this . gridOptions . enablePagination ) || false ;
672681
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- }
681682 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 ;
684685 }
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 ;
686696 }
687697
688698 // 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