谁能建议在网站上制作动态表格的最佳方法?我希望表格是可配置的。
最佳答案
这是我写的表格组件
https://stackblitz.com/edit/angular-xdn6nq
要使用它,您需要为其提供一个数据数组和一个 TableConfig 对象。
<app-table [data]="data" [config]="tableConfig"></app-table>
表配置对象有接口(interface)
interface TableConfig {
columns: ColumnConfig<any>[];
columnGroups?: ColumnGroup[];
filters?: ((item: any) => boolean)[];
groupBy?: GroupBy;
update?: Subject<boolean>;
}
Columns 是你要设置的主要属性,它是一个 ColumnConfig 的数组,有接口(interface)
interface ColumnConfig<T> {
property: string;
type?: ColumnType;
heading?: string;
sortable?: boolean;
direction?: ColumnSortDirection;
compare?: (a: T, b: T) => number; // Return -1 if a is less than b by some ordering criterion, 0 if equal, 1 a is greater than b by the ordering criterion
display?: (item: T) => string;
route?: (item: T) => string;
href?: (item: T) => string;
}
关于javascript - 在 Angular 6 中制作动态和可配置表的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54566142/