66 Component ,
77 computed ,
88 ContentChild ,
9+ contentChild ,
910 contentChildren ,
1011 DoCheck ,
1112 effect ,
@@ -26,8 +27,7 @@ import {
2627 signal ,
2728 TemplateRef ,
2829 untracked ,
29- viewChild ,
30- ViewChild
30+ viewChild
3131} from '@angular/core' ;
3232import { Subscription } from 'rxjs' ;
3333
@@ -609,34 +609,31 @@ export class DatatableComponent<TRow extends Row = any>
609609
610610 /**
611611 * Footer template gathered from the ContentChild
612+ * @internal
612613 */
613- @ContentChild ( DatatableFooterDirective )
614- footer ?: DatatableFooterDirective ;
614+ readonly _footer = contentChild ( DatatableFooterDirective ) ;
615615
616616 /**
617617 * Reference to the body component for manually
618618 * invoking functions on the body.
619619 */
620- @ViewChild ( DataTableBodyComponent )
621- bodyComponent ! : DataTableBodyComponent < TRow & { treeStatus ?: TreeStatus } > ;
622-
623- /**
624- * Reference to the header component for manually
625- * invoking functions on the header.
626- */
627- @ViewChild ( DataTableHeaderComponent )
628- headerComponent ! : DataTableHeaderComponent ;
620+ private readonly _bodyComponent =
621+ viewChild . required < DataTableBodyComponent < TRow & { treeStatus ?: TreeStatus } > > (
622+ DataTableBodyComponent
623+ ) ;
629624
630- @ViewChild ( DataTableHeaderComponent , { read : ElementRef } )
631- headerElement ?: ElementRef < HTMLElement > ;
625+ private readonly _headerElement = viewChild ( DataTableHeaderComponent , {
626+ read : ElementRef < HTMLElement >
627+ } ) ;
632628
633- @ViewChild ( DataTableBodyComponent , { read : ElementRef } )
634- private bodyElement ! : ElementRef < HTMLElement > ;
629+ private readonly _bodyElement = viewChild . required ( DataTableBodyComponent , {
630+ read : ElementRef < HTMLElement >
631+ } ) ;
635632
636- @ContentChild ( DatatableRowDefDirective , {
633+ /** @internal */
634+ readonly _rowDefTemplate = contentChild ( DatatableRowDefDirective , {
637635 read : TemplateRef
638- } )
639- rowDefTemplate ?: TemplateRef < any > ;
636+ } ) ;
640637
641638 /**
642639 * Returns if all rows are selected.
@@ -645,9 +642,10 @@ export class DatatableComponent<TRow extends Row = any>
645642 const selected = this . selected ( ) ;
646643 let allRowsSelected = this . rows ( ) && selected && selected . length === this . rows ( ) ! . length ;
647644
648- if ( this . bodyComponent && this . selectAllRowsOnPage ( ) ) {
649- const indexes = this . bodyComponent . indexes ;
650- const rowsOnPage = indexes ( ) . last - indexes ( ) . first ;
645+ const bodyComponent = this . _bodyComponent ( ) ;
646+ if ( bodyComponent && this . selectAllRowsOnPage ( ) ) {
647+ const indexes = bodyComponent . indexes ( ) ;
648+ const rowsOnPage = indexes . last - indexes . first ;
651649 allRowsSelected = selected . length === rowsOnPage ;
652650 }
653651
@@ -660,8 +658,9 @@ export class DatatableComponent<TRow extends Row = any>
660658 readonly bodyHeight = computed ( ( ) => {
661659 if ( this . scrollbarV ( ) ) {
662660 let height = this . dimensions ( ) . height ;
663- if ( this . headerElement ) {
664- height = height - this . headerElement . nativeElement . getBoundingClientRect ( ) . height ;
661+ const headerElement = this . _headerElement ( ) ;
662+ if ( headerElement ) {
663+ height = height - headerElement . nativeElement . getBoundingClientRect ( ) . height ;
665664 }
666665 return height - this . footerHeight ( ) ;
667666 }
@@ -920,7 +919,7 @@ export class DatatableComponent<TRow extends Row = any>
920919 if ( ! width ) {
921920 return [ ] ;
922921 }
923- const bodyElement = this . bodyElement ? .nativeElement ;
922+ const bodyElement = this . _bodyElement ( ) . nativeElement ;
924923 this . verticalScrollVisible = bodyElement ?. scrollHeight > bodyElement ?. clientHeight ;
925924 if ( this . scrollbarV ( ) || this . scrollbarVDynamic ( ) ) {
926925 width =
@@ -1001,7 +1000,7 @@ export class DatatableComponent<TRow extends Row = any>
10011000 */
10021001 onFooterPage ( event : PagerPageEvent ) {
10031002 this . offset = event . page - 1 ;
1004- this . bodyComponent . updateOffsetY ( this . offset ) ;
1003+ this . _bodyComponent ( ) . updateOffsetY ( this . offset ) ;
10051004
10061005 this . page . emit ( {
10071006 count : this . count ( ) ,
@@ -1156,7 +1155,7 @@ export class DatatableComponent<TRow extends Row = any>
11561155
11571156 // Always go to first page when sorting to see the newly sorted data
11581157 this . offset = 0 ;
1159- this . bodyComponent . updateOffsetY ( this . offset ) ;
1158+ this . _bodyComponent ( ) . updateOffsetY ( this . offset ) ;
11601159 // Emit the page object with updated offset value
11611160 this . page . emit ( {
11621161 count : this . count ( ) ,
@@ -1172,10 +1171,10 @@ export class DatatableComponent<TRow extends Row = any>
11721171 * Toggle all row selection
11731172 */
11741173 onHeaderSelect ( ) : void {
1175- if ( this . bodyComponent && this . selectAllRowsOnPage ( ) ) {
1174+ const bodyComponent = this . _bodyComponent ( ) ;
1175+ if ( bodyComponent && this . selectAllRowsOnPage ( ) ) {
11761176 // before we splice, chk if we currently have all selected
1177- const first = this . bodyComponent . indexes ( ) . first ;
1178- const last = this . bodyComponent . indexes ( ) . last ;
1177+ const { first, last } = bodyComponent . indexes ( ) ;
11791178 const allSelected = this . selected ( ) . length === last - first ;
11801179
11811180 // do the opposite here
0 commit comments