@@ -9,6 +9,7 @@ import type {
9
9
import {
10
10
addToArrayWhenNotExists ,
11
11
castObservableToPromise ,
12
+ createDomElement ,
12
13
SlickEventData ,
13
14
SlickRowSelectionModel ,
14
15
unsubscribeAll ,
@@ -119,15 +120,12 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
119
120
// when those are Angular View/ViewModel, we need to create View Component & provide the html containers to the Plugin (preTemplate/postTemplate methods)
120
121
if ( ! this . gridOptions . rowDetailView . preTemplate ) {
121
122
this . _preloadComponent = this . gridOptions ?. rowDetailView ?. preloadComponent ;
122
- this . addonOptions . preTemplate = ( ) =>
123
- this . _grid . sanitizeHtmlString ( `<div class="${ PRELOAD_CONTAINER_PREFIX } "></div>` ) as string ;
123
+ this . addonOptions . preTemplate = ( ) => createDomElement ( 'div' , { className : `${ PRELOAD_CONTAINER_PREFIX } ` } ) ;
124
124
}
125
125
if ( ! this . gridOptions . rowDetailView . postTemplate ) {
126
126
this . _viewComponent = this . gridOptions ?. rowDetailView ?. viewComponent ;
127
127
this . addonOptions . postTemplate = ( itemDetail : any ) =>
128
- this . _grid . sanitizeHtmlString (
129
- `<div class="${ ROW_DETAIL_CONTAINER_PREFIX } ${ itemDetail [ this . datasetIdPropName ] } "></div>`
130
- ) as string ;
128
+ createDomElement ( 'div' , { className : `${ ROW_DETAIL_CONTAINER_PREFIX } ${ itemDetail [ this . datasetIdPropName ] } ` } ) ;
131
129
}
132
130
133
131
// this also requires the Row Selection Model to be registered as well
@@ -247,21 +245,19 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
247
245
248
246
/** Redraw the necessary View Component */
249
247
redrawViewComponent ( createdView : CreatedView ) {
250
- const containerElements = this . gridContainerElement . getElementsByClassName ( ` ${ ROW_DETAIL_CONTAINER_PREFIX } ${ createdView . id } `) ;
251
- if ( containerElements ?. length >= 0 ) {
248
+ const containerElement = this . gridContainerElement . querySelector ( `. ${ ROW_DETAIL_CONTAINER_PREFIX } ${ createdView . id } `) ;
249
+ if ( containerElement ) {
252
250
this . renderViewModel ( createdView . dataContext ) ;
253
251
}
254
252
}
255
253
256
254
/** Render (or re-render) the View Component (Row Detail) */
257
255
renderPreloadView ( ) {
258
- const containerElements = this . gridContainerElement . getElementsByClassName (
259
- `${ PRELOAD_CONTAINER_PREFIX } `
260
- ) as HTMLCollectionOf < HTMLElement > ;
261
- if ( this . _preloadComponent && containerElements ?. length >= 0 ) {
256
+ const containerElement = this . gridContainerElement . querySelector ( `.${ PRELOAD_CONTAINER_PREFIX } ` ) ;
257
+ if ( this . _preloadComponent && containerElement ) {
262
258
const preloadComp = this . angularUtilService . createAngularComponentAppendToDom (
263
259
this . _preloadComponent ,
264
- containerElements [ containerElements . length - 1 ] ,
260
+ containerElement ,
265
261
{ } ,
266
262
{ sanitizer : this . _grid . sanitizeHtmlString }
267
263
) ;
@@ -271,15 +267,14 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
271
267
272
268
/** Render (or re-render) the View Component (Row Detail) */
273
269
renderViewModel ( item : any ) : CreatedView | undefined {
274
- const containerElements = this . gridContainerElement . getElementsByClassName (
275
- `${ ROW_DETAIL_CONTAINER_PREFIX } ${ item [ this . datasetIdPropName ] } `
276
- ) as HTMLCollectionOf < HTMLElement > ;
277
-
278
- if ( this . _viewComponent && containerElements ?. length > 0 ) {
270
+ const containerElement = this . gridContainerElement . querySelector (
271
+ `.${ ROW_DETAIL_CONTAINER_PREFIX } ${ item [ this . datasetIdPropName ] } `
272
+ ) ;
273
+ if ( this . _viewComponent && containerElement ) {
279
274
// render row detail
280
275
const componentOutput = this . angularUtilService . createAngularComponentAppendToDom (
281
276
this . _viewComponent ,
282
- containerElements [ containerElements . length - 1 ] ,
277
+ containerElement ,
283
278
{
284
279
model : item ,
285
280
addon : this ,
@@ -291,6 +286,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
291
286
sanitizer : this . _grid . sanitizeHtmlString ,
292
287
}
293
288
) ;
289
+
294
290
if ( componentOutput ?. componentRef ) {
295
291
const viewObj = this . _views . find ( ( obj ) => obj . id === item [ this . datasetIdPropName ] ) ;
296
292
if ( viewObj ) {
@@ -309,22 +305,21 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
309
305
310
306
protected disposeViewByItem ( item : any , removeFromArray = false ) : void {
311
307
const foundViewIndex = this . _views . findIndex ( ( view : CreatedView ) => view . id === item [ this . datasetIdPropName ] ) ;
312
- if ( foundViewIndex >= 0 && foundViewIndex in this . _views ) {
313
- const expandedView = this . _views [ foundViewIndex ] ;
314
- this . disposeView ( expandedView ) ;
308
+ if ( foundViewIndex >= 0 ) {
309
+ this . disposeView ( this . _views [ foundViewIndex ] ) ;
315
310
if ( removeFromArray ) {
316
311
this . _views . splice ( foundViewIndex , 1 ) ;
317
312
}
318
313
}
319
314
}
320
315
321
316
protected disposeView ( expandedView : CreatedView ) : CreatedView | void {
317
+ expandedView . rendered = false ;
322
318
const compRef = expandedView ?. componentRef ;
323
319
if ( compRef ) {
324
320
this . appRef . detachView ( compRef . hostView ) ;
325
321
if ( typeof compRef ?. destroy === 'function' ) {
326
322
compRef . destroy ( ) ;
327
- expandedView . rendered = false ;
328
323
}
329
324
return expandedView ;
330
325
}
@@ -358,8 +353,10 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
358
353
}
359
354
360
355
if ( ! awaitedItemDetail || ! ( this . datasetIdPropName in awaitedItemDetail ) ) {
361
- throw new Error ( `[Angular-Slickgrid] could not process the Row Detail, you must make sure that your "process" callback
362
- (a Promise or an HttpClient call returning an Observable) returns an item object that has an "${ this . datasetIdPropName } " property` ) ;
356
+ throw new Error (
357
+ '[Angular-Slickgrid] could not process the Row Detail, you must make sure that your "process" callback ' +
358
+ `returns an item object that has an "${ this . datasetIdPropName } " property`
359
+ ) ;
363
360
}
364
361
365
362
// notify the plugin with the new item details
@@ -382,8 +379,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
382
379
dataContext : args . item ,
383
380
rendered : false ,
384
381
} ;
385
- const idPropName = this . gridOptions . datasetIdPropertyName || 'id' ;
386
- addToArrayWhenNotExists ( this . _views , viewInfo , idPropName ) ;
382
+ addToArrayWhenNotExists ( this . _views , viewInfo , this . datasetIdPropName ) ;
387
383
} else {
388
384
// collapsing, so dispose of the View/Component
389
385
this . disposeViewByItem ( args . item , true ) ;
@@ -392,7 +388,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
392
388
393
389
/** When Row comes back to Viewport Range, we need to redraw the View */
394
390
protected handleOnRowBackToViewportRange ( _e : SlickEventData < OnRowBackToViewportRangeArgs > , args : OnRowBackToViewportRangeArgs ) {
395
- const viewModel = Array . from ( this . _views ) . find ( ( x ) => x . id === args . rowId ) ;
391
+ const viewModel = this . _views . find ( ( x ) => x . id === args . rowId ) ;
396
392
if ( viewModel && ! viewModel . rendered ) {
397
393
this . redrawViewComponent ( viewModel ) ;
398
394
}
0 commit comments