mirror of https://github.com/abpframework/abp.git
5 changed files with 106 additions and 6 deletions
@ -0,0 +1,26 @@ |
|||
<div class="ui-table ui-widget" [style.max-height.px]="maxHeight"> |
|||
<div class="ui-table-wrapper"> |
|||
<div class="ui-table-scrollable-wrapper"> |
|||
<table> |
|||
<colgroup> |
|||
<ng-container *ngTemplateOutlet="colgroupTemplate"></ng-container> |
|||
</colgroup> |
|||
<thead class="ui-table-thead"> |
|||
<ng-container *ngTemplateOutlet="headerTemplate"></ng-container> |
|||
</thead> |
|||
<tbody class="ui-table-tbody"> |
|||
<ng-container |
|||
*ngFor="let val of slicedValue" |
|||
[ngTemplateOutlet]="bodyTemplate" |
|||
[ngTemplateOutletContext]="{ $implicit: val }" |
|||
></ng-container> |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
<abp-paginator |
|||
*ngIf="rows" |
|||
[totalPages]="totalPages" |
|||
(valueChange)="page = $event; pageChange.emit($event)" |
|||
></abp-paginator> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,3 @@ |
|||
.ui-table-scrollable-wrapper { |
|||
overflow: auto; |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
import { Component, OnInit, Input, TemplateRef, Output, EventEmitter } from '@angular/core'; |
|||
|
|||
@Component({ |
|||
selector: 'abp-table', |
|||
templateUrl: 'table.component.html', |
|||
styleUrls: ['table.component.scss'], |
|||
}) |
|||
export class TableComponent implements OnInit { |
|||
private _totalRecords: number; |
|||
|
|||
@Input() |
|||
value: any[]; |
|||
|
|||
@Input() |
|||
headerTemplate: TemplateRef<any>; |
|||
|
|||
@Input() |
|||
bodyTemplate: TemplateRef<any>; |
|||
|
|||
@Input() |
|||
colgroupTemplate: TemplateRef<any>; |
|||
|
|||
@Input() |
|||
maxHeight: number; |
|||
|
|||
@Input() |
|||
rows: number; |
|||
|
|||
@Output() |
|||
readonly pageChange = new EventEmitter<number>(); |
|||
|
|||
page = 1; |
|||
|
|||
@Input() |
|||
get totalRecords(): number { |
|||
return this._totalRecords || this.value.length; |
|||
} |
|||
set totalRecords(newValue: number) { |
|||
if (newValue < 0) this._totalRecords = 0; |
|||
|
|||
this._totalRecords = newValue; |
|||
} |
|||
|
|||
get totalPages(): number { |
|||
if (!this.rows) { |
|||
return; |
|||
} |
|||
|
|||
return Math.ceil(this.totalRecords / this.rows); |
|||
} |
|||
|
|||
get slicedValue(): any[] { |
|||
if (!this.rows || this.rows > this.value.length) { |
|||
return this.value; |
|||
} |
|||
|
|||
const start = (this.page - 1) * this.rows; |
|||
return this.value.slice(start, start + this.rows); |
|||
} |
|||
|
|||
constructor() {} |
|||
|
|||
ngOnInit() {} |
|||
} |
|||
Loading…
Reference in new issue