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,27 @@ 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
616- /**
617- * Reference to the body component for manually
618- * invoking functions on the body.
619- */
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 ;
616+ private readonly _bodyComponent =
617+ viewChild . required < DataTableBodyComponent < TRow & { treeStatus ?: TreeStatus } > > (
618+ DataTableBodyComponent
619+ ) ;
629620
630- @ViewChild ( DataTableHeaderComponent , { read : ElementRef } )
631- headerElement ?: ElementRef < HTMLElement > ;
621+ private readonly _headerElement = viewChild ( DataTableHeaderComponent , {
622+ read : ElementRef < HTMLElement >
623+ } ) ;
632624
633- @ViewChild ( DataTableBodyComponent , { read : ElementRef } )
634- private bodyElement ! : ElementRef < HTMLElement > ;
625+ private readonly _bodyElement = viewChild . required ( DataTableBodyComponent , {
626+ read : ElementRef < HTMLElement >
627+ } ) ;
635628
636- @ContentChild ( DatatableRowDefDirective , {
629+ /** @internal */
630+ readonly _rowDefTemplate = contentChild ( DatatableRowDefDirective , {
637631 read : TemplateRef
638- } )
639- rowDefTemplate ?: TemplateRef < any > ;
632+ } ) ;
640633
641634 /**
642635 * Returns if all rows are selected.
@@ -645,9 +638,9 @@ export class DatatableComponent<TRow extends Row = any>
645638 const selected = this . selected ( ) ;
646639 let allRowsSelected = this . rows ( ) && selected && selected . length === this . rows ( ) ! . length ;
647640
648- if ( this . bodyComponent && this . selectAllRowsOnPage ( ) ) {
649- const indexes = this . bodyComponent . indexes ;
650- const rowsOnPage = indexes ( ) . last - indexes ( ) . first ;
641+ if ( this . selectAllRowsOnPage ( ) ) {
642+ const { first , last } = this . _bodyComponent ( ) . indexes ( ) ;
643+ const rowsOnPage = last - first ;
651644 allRowsSelected = selected . length === rowsOnPage ;
652645 }
653646
@@ -660,8 +653,9 @@ export class DatatableComponent<TRow extends Row = any>
660653 readonly bodyHeight = computed ( ( ) => {
661654 if ( this . scrollbarV ( ) ) {
662655 let height = this . dimensions ( ) . height ;
663- if ( this . headerElement ) {
664- height = height - this . headerElement . nativeElement . getBoundingClientRect ( ) . height ;
656+ const headerElement = this . _headerElement ( ) ;
657+ if ( headerElement ) {
658+ height = height - headerElement . nativeElement . getBoundingClientRect ( ) . height ;
665659 }
666660 return height - this . footerHeight ( ) ;
667661 }
@@ -920,8 +914,8 @@ export class DatatableComponent<TRow extends Row = any>
920914 if ( ! width ) {
921915 return [ ] ;
922916 }
923- const bodyElement = this . bodyElement ? .nativeElement ;
924- this . verticalScrollVisible = bodyElement ?. scrollHeight > bodyElement ?. clientHeight ;
917+ const { scrollHeight , clientHeight } = this . _bodyElement ( ) . nativeElement ;
918+ this . verticalScrollVisible = scrollHeight > clientHeight ;
925919 if ( this . scrollbarV ( ) || this . scrollbarVDynamic ( ) ) {
926920 width =
927921 width -
@@ -1001,7 +995,7 @@ export class DatatableComponent<TRow extends Row = any>
1001995 */
1002996 onFooterPage ( event : PagerPageEvent ) {
1003997 this . offset = event . page - 1 ;
1004- this . bodyComponent . updateOffsetY ( this . offset ) ;
998+ this . _bodyComponent ( ) . updateOffsetY ( this . offset ) ;
1005999
10061000 this . page . emit ( {
10071001 count : this . count ( ) ,
@@ -1156,7 +1150,7 @@ export class DatatableComponent<TRow extends Row = any>
11561150
11571151 // Always go to first page when sorting to see the newly sorted data
11581152 this . offset = 0 ;
1159- this . bodyComponent . updateOffsetY ( this . offset ) ;
1153+ this . _bodyComponent ( ) . updateOffsetY ( this . offset ) ;
11601154 // Emit the page object with updated offset value
11611155 this . page . emit ( {
11621156 count : this . count ( ) ,
@@ -1172,10 +1166,9 @@ export class DatatableComponent<TRow extends Row = any>
11721166 * Toggle all row selection
11731167 */
11741168 onHeaderSelect ( ) : void {
1175- if ( this . bodyComponent && this . selectAllRowsOnPage ( ) ) {
1169+ if ( this . selectAllRowsOnPage ( ) ) {
11761170 // before we splice, chk if we currently have all selected
1177- const first = this . bodyComponent . indexes ( ) . first ;
1178- const last = this . bodyComponent . indexes ( ) . last ;
1171+ const { first, last } = this . _bodyComponent ( ) . indexes ( ) ;
11791172 const allSelected = this . selected ( ) . length === last - first ;
11801173
11811174 // do the opposite here
0 commit comments