@@ -29,6 +29,7 @@ import { SharedService } from './shared.service';
2929
3030@Injectable ( )
3131export class ExtensionService {
32+ private _extensionCreatedList : any [ ] = [ ] ;
3233 private _extensionList : ExtensionModel [ ] = [ ] ;
3334
3435 constructor (
@@ -82,7 +83,7 @@ export class ExtensionService {
8283 * @param name
8384 */
8485 getExtensionByName ( name : ExtensionName ) : ExtensionModel | undefined {
85- return this . _extensionList . find ( ( p ) => p . name === name ) ;
86+ return Array . isArray ( this . _extensionList ) && this . _extensionList . find ( ( p ) => p . name === name ) ;
8687 }
8788
8889 /**
@@ -131,11 +132,22 @@ export class ExtensionService {
131132 }
132133 }
133134
135+ // Row Selection Plugin
136+ // this extension should be registered BEFORE the Checkbox Selector & Row Detail since it can be use by these 2 plugins
137+ if ( ! this . getExtensionByName ( ExtensionName . rowSelection ) && ( this . sharedService . gridOptions . enableRowSelection || this . sharedService . gridOptions . enableCheckboxSelector || this . sharedService . gridOptions . enableRowDetailView ) ) {
138+ if ( this . rowSelectionExtension && this . rowSelectionExtension . register ) {
139+ const instance = this . rowSelectionExtension . register ( ) ;
140+ this . _extensionList . push ( { name : ExtensionName . rowSelection , class : this . rowSelectionExtension , addon : instance , instance } ) ;
141+ }
142+ }
143+
134144 // Checkbox Selector Plugin
135145 if ( this . sharedService . gridOptions . enableCheckboxSelector ) {
136146 if ( this . checkboxSelectorExtension && this . checkboxSelectorExtension . register ) {
137147 const rowSelectionExtension = this . getExtensionByName ( ExtensionName . rowSelection ) ;
138- const instance = this . checkboxSelectorExtension . register ( rowSelectionExtension ) ;
148+ this . checkboxSelectorExtension . register ( rowSelectionExtension ) ;
149+ const createdExtension = this . getCreatedExtensionByName ( ExtensionName . checkboxSelector ) ; // get the instance from when it was really created earlier
150+ const instance = createdExtension && createdExtension . instance ;
139151 this . _extensionList . push ( { name : ExtensionName . checkboxSelector , class : this . checkboxSelectorExtension , addon : instance , instance } ) ;
140152 }
141153 }
@@ -193,7 +205,9 @@ export class ExtensionService {
193205 if ( this . sharedService . gridOptions . enableRowDetailView ) {
194206 if ( this . rowDetailViewExtension && this . rowDetailViewExtension . register ) {
195207 const rowSelectionExtension = this . getExtensionByName ( ExtensionName . rowSelection ) ;
196- const instance = this . rowDetailViewExtension . register ( rowSelectionExtension ) ;
208+ this . rowDetailViewExtension . register ( rowSelectionExtension ) ;
209+ const createdExtension = this . getCreatedExtensionByName ( ExtensionName . rowDetailView ) ; // get the plugin from when it was really created earlier
210+ const instance = createdExtension && createdExtension . instance ;
197211 this . _extensionList . push ( { name : ExtensionName . rowDetailView , class : this . rowDetailViewExtension , addon : instance , instance } ) ;
198212 }
199213 }
@@ -206,14 +220,6 @@ export class ExtensionService {
206220 }
207221 }
208222
209- // Row Selection Plugin
210- if ( ! this . sharedService . gridOptions . enableCheckboxSelector && this . sharedService . gridOptions . enableRowSelection ) {
211- if ( this . rowSelectionExtension && this . rowSelectionExtension . register ) {
212- const instance = this . rowSelectionExtension . register ( ) ;
213- this . _extensionList . push ( { name : ExtensionName . rowSelection , class : this . rowSelectionExtension , addon : instance , instance } ) ;
214- }
215- }
216-
217223 // manually register other plugins
218224 if ( this . sharedService . gridOptions . registerPlugins !== undefined ) {
219225 if ( Array . isArray ( this . sharedService . gridOptions . registerPlugins ) ) {
@@ -239,14 +245,23 @@ export class ExtensionService {
239245 */
240246 createExtensionsBeforeGridCreation ( columnDefinitions : Column [ ] , options : GridOption ) {
241247 if ( options . enableCheckboxSelector ) {
242- this . checkboxSelectorExtension . create ( columnDefinitions , options ) ;
248+ if ( ! this . getCreatedExtensionByName ( ExtensionName . checkboxSelector ) ) {
249+ const checkboxInstance = this . checkboxSelectorExtension . create ( columnDefinitions , options ) ;
250+ this . _extensionCreatedList . push ( { name : ExtensionName . checkboxSelector , instance : checkboxInstance } ) ;
251+ }
243252 }
244253 if ( options . enableRowDetailView ) {
245- this . rowDetailViewExtension . create ( columnDefinitions , options ) ;
254+ if ( ! this . getCreatedExtensionByName ( ExtensionName . rowDetailView ) ) {
255+ const rowDetailInstance = this . rowDetailViewExtension . create ( columnDefinitions , options ) ;
256+ this . _extensionCreatedList . push ( { name : ExtensionName . rowDetailView , instance : rowDetailInstance } ) ;
257+ }
246258 }
247259 if ( options . enableDraggableGrouping ) {
248- const plugin = this . draggableGroupingExtension . create ( options ) ;
249- options . enableColumnReorder = plugin . getSetupColumnReorder ;
260+ if ( ! this . getCreatedExtensionByName ( ExtensionName . rowDetailView ) ) {
261+ const draggableInstance = this . draggableGroupingExtension . create ( options ) ;
262+ options . enableColumnReorder = draggableInstance . getSetupColumnReorder ;
263+ this . _extensionCreatedList . push ( { name : ExtensionName . draggableGrouping , instance : draggableInstance } ) ;
264+ }
250265 }
251266 }
252267
@@ -350,6 +365,18 @@ export class ExtensionService {
350365 }
351366 }
352367
368+ //
369+ // private functions
370+ // -------------------
371+
372+ /**
373+ * Get an Extension that was created by calling its "create" method (there are only 3 extensions which uses this method)
374+ * @param name
375+ */
376+ private getCreatedExtensionByName ( name : ExtensionName ) : ExtensionModel | undefined {
377+ return Array . isArray ( this . _extensionCreatedList ) && this . _extensionCreatedList . find ( ( p ) => p . name === name ) ;
378+ }
379+
353380 /** Translate an array of items from an input key and assign translated value to the output key */
354381 private translateItems ( items : any [ ] , inputKey : string , outputKey : string ) {
355382 if ( Array . isArray ( items ) ) {
0 commit comments