From 704ea8221e6a6a198811c91f2a5fd15ed25c46da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Fri, 27 Aug 2021 20:16:49 +0300 Subject: [PATCH] Get table properties from parent component --- src/lib/listing/listing-component.directive.ts | 4 ++++ src/lib/listing/table/table.component.ts | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lib/listing/listing-component.directive.ts b/src/lib/listing/listing-component.directive.ts index 9c212f5..23372a8 100644 --- a/src/lib/listing/listing-component.directive.ts +++ b/src/lib/listing/listing-component.directive.ts @@ -20,7 +20,11 @@ export abstract class ListingComponent extends AutoUnsubscri readonly noMatch$ = this._noMatch$; readonly sortedDisplayedEntities$ = this._sortedDisplayedEntities$; + // TODO: These should be somewhere in table listing, not generic listing abstract readonly tableColumnConfigs: readonly TableColumnConfig[]; + readonly tableHeaderLabel?: string; + readonly routerLinkFn?: (entity: T) => string | string[]; + /** * Key used in the *trackBy* function with **ngFor* or **cdkVirtualFor* * and in the default sorting and as the search field diff --git a/src/lib/listing/table/table.component.ts b/src/lib/listing/table/table.component.ts index 1939c36..2ac2934 100644 --- a/src/lib/listing/table/table.component.ts +++ b/src/lib/listing/table/table.component.ts @@ -28,20 +28,20 @@ export class TableComponent implements OnInit { @Input() actionsTemplate?: TemplateRef; @Input() headerTemplate?: TemplateRef; @Input() @Required() itemSize!: number; - @Input() @Required() tableColumnConfigs!: readonly TableColumnConfig[]; - @Input() @Required() tableHeaderLabel!: string; @Input() selectionEnabled = false; @Input() hasScrollButton = false; @Input() emptyColumnWidth?: string; @Input() classes?: string; - @Input() routerLinkFn?: (entity: T) => string | string[]; @Input() noDataText?: string; @Input() noDataIcon?: string; @Input() noDataButtonLabel?: string; @Input() showNoDataButton = false; @Output() readonly noDataAction = new EventEmitter(); @Input() noMatchText?: string; - @ViewChild(CdkVirtualScrollViewport, { static: true }) private readonly _viewport!: CdkVirtualScrollViewport; + routerLinkFn?: (entity: T) => string | string[]; + tableColumnConfigs!: readonly TableColumnConfig[]; + tableHeaderLabel?: string; // todo not optional + @ViewChild(CdkVirtualScrollViewport, { static: true }) readonly scrollViewport!: CdkVirtualScrollViewport; constructor(@Inject(forwardRef(() => ListingComponent)) private _parent: ListingComponent) {} @@ -50,6 +50,10 @@ export class TableComponent implements OnInit { } ngOnInit(): void { + this.tableColumnConfigs = this.listingComponent.tableColumnConfigs; + this.tableHeaderLabel = this.listingComponent.tableHeaderLabel; + this.routerLinkFn = this.listingComponent.routerLinkFn; + this._patchConfig(); this._setStyles(); } @@ -59,7 +63,7 @@ export class TableComponent implements OnInit { } private _setStyles(): void { - const element = this._viewport.elementRef.nativeElement; + const element = this.scrollViewport.elementRef.nativeElement; this._setColumnsWidth(element); this._setItemSize(element); this._setPadding(element);