Browse Source

feat(theme-shared): add empty template to table component

#2537
pull/2605/head
mehmet-erim 7 years ago
parent
commit
9d448efd67
  1. 16
      npm/ng-packs/packages/theme-shared/src/lib/components/table/table.component.html
  2. 22
      npm/ng-packs/packages/theme-shared/src/lib/components/table/table.component.ts

16
npm/ng-packs/packages/theme-shared/src/lib/components/table/table.component.html

@ -1,4 +1,4 @@
<div class="ui-table ui-widget"> <div #wrapper class="ui-table ui-widget">
<div class="ui-table-wrapper"> <div class="ui-table-wrapper">
<ng-container <ng-container
*ngTemplateOutlet="scrollable ? scrollableTemplate : defaultTemplate" *ngTemplateOutlet="scrollable ? scrollableTemplate : defaultTemplate"
@ -58,9 +58,21 @@
<ng-template #body> <ng-template #body>
<tbody class="ui-table-tbody"> <tbody class="ui-table-tbody">
<ng-container <ng-container
*ngTemplateOutlet="value && value.length ? container : emptyTemplate"
></ng-container>
<ng-template
#container
*ngFor="let val of slicedValue; trackBy: trackByFn" *ngFor="let val of slicedValue; trackBy: trackByFn"
[ngTemplateOutlet]="bodyTemplate" [ngTemplateOutlet]="bodyTemplate"
[ngTemplateOutletContext]="{ $implicit: val }" [ngTemplateOutletContext]="{ $implicit: val }"
></ng-container> ></ng-template>
</tbody> </tbody>
</ng-template> </ng-template>
<ng-template #emptyTemplate>
<tr>
<td class="text-center" [attr.colspan]="colspan">
{{ emptyMessage | abpLocalization }}
</td>
</tr>
</ng-template>

22
npm/ng-packs/packages/theme-shared/src/lib/components/table/table.component.ts

@ -1,18 +1,20 @@
import { import {
AfterViewInit,
Component, Component,
OnInit, ElementRef,
EventEmitter,
Input, Input,
TemplateRef,
Output, Output,
EventEmitter, TemplateRef,
TrackByFunction, TrackByFunction,
ViewChild,
} from '@angular/core'; } from '@angular/core';
@Component({ @Component({
selector: 'abp-table', selector: 'abp-table',
templateUrl: 'table.component.html', templateUrl: 'table.component.html',
}) })
export class TableComponent implements OnInit { export class TableComponent implements AfterViewInit {
private _totalRecords: number; private _totalRecords: number;
@Input() @Input()
@ -39,13 +41,21 @@ export class TableComponent implements OnInit {
@Input() @Input()
trackingProp = 'id'; trackingProp = 'id';
@Input()
emptyMessage = 'AbpAccount::NoDataAvailableInDatatable';
@Output() @Output()
readonly pageChange = new EventEmitter<number>(); readonly pageChange = new EventEmitter<number>();
@ViewChild('wrapper', { read: ElementRef, static: false })
wrapperRef: ElementRef<HTMLDivElement>;
page = 1; page = 1;
bodyScrollLeft = 0; bodyScrollLeft = 0;
colspan = 1;
trackByFn: TrackByFunction<any> = (_, value) => { trackByFn: TrackByFunction<any> = (_, value) => {
return typeof value === 'object' ? value[this.trackingProp] || value : value; return typeof value === 'object' ? value[this.trackingProp] || value : value;
}; };
@ -79,5 +89,7 @@ export class TableComponent implements OnInit {
constructor() {} constructor() {}
ngOnInit() {} ngAfterViewInit() {
this.colspan = this.wrapperRef.nativeElement.querySelectorAll('th').length;
}
} }

Loading…
Cancel
Save