我需要使用一个带有角度4和bootstrap 4的表,但是bootstrap 4官方表看起来并不太好.
我找到了这个git项目:
https://www.npmjs.com/package/angular-4-data-table-fix
我找到了这个git项目:
https://www.npmjs.com/package/angular-4-data-table-fix
但无法找到有关如何使用它的任何文档.
有谁知道这个项目或类似的项目,可以帮助吗?
谢谢.
你可以在这里看到代码:
https://github.com/ggmod/angular-2-data-table-demo/tree/master/app
原文链接:https://www.f2er.com/angularjs/141501.html基本上,您为表创建一个新组件,如下所示(取自上面的示例):
import { Component } from '@angular/core'; import { DataTableResource } from 'angular-2-data-table'; import persons from './data-table-demo1-data'; @Component({ selector: 'data-table-demo-1',providers: [],templateUrl: 'app/demo1/data-table-demo1.html',styleUrls: ['app/demo1/data-table-demo1.css'] }) export class DataTableDemo1 { itemResource = new DataTableResource(persons); items = []; itemCount = 0; constructor() { this.itemResource.count().then(count => this.itemCount = count); } reloadItems(params) { this.itemResource.query(params).then(items => this.items = items); } // special properties: rowClick(rowEvent) { console.log('Clicked: ' + rowEvent.row.item.name); } rowDoubleClick(rowEvent) { alert('Double clicked: ' + rowEvent.row.item.name); } rowTooltip(item) { return item.jobTitle; } }
和模板HTML文件:
<div style="margin: auto; max-width: 1000px; margin-bottom: 50px;"> <data-table id="persons-grid" headerTitle="Employees" [items]="items" [itemCount]="itemCount" (reload)="reloadItems($event)" (rowClick)="rowClick($event)" (rowDoubleClick)="rowDoubleClick($event)" [rowTooltip]="rowTooltip" > <data-table-column [property]="'name'" [header]="'Name'" [sortable]="true" [resizable]="true"> </data-table-column> <data-table-column [property]="'date'" [header]="'Date'" [sortable]="true"> <template #dataTableCell let-item="item"> <span>{{item.date | date:'yyyy-MM-dd'}}</span> </template> </data-table-column> <data-table-column property="phoneNumber" header="Phone number" width="150px"> </data-table-column> <data-table-column [property]="'jobTitle'" [header]="'Job title'" [visible]="false"> </data-table-column> <data-table-column [property]="'active'" [header]="'Active'" [width]="100" [resizable]="true"> <template #dataTableHeader let-item="item"> <span style="color: rgb(232,0)">Active</span> </template> <template #dataTableCell let-item="item"> <span style="color: grey"> <span class="glyphicon glyphicon-ok" *ngIf="item.active"></span> <span class="glyphicon glyphicon-remove" *ngIf="!item.active"></span> </span> </template> </data-table-column> </data-table> </div>
当然,在您的情况下,数据源和结构可能不同,因此您需要将此代码调整为所需的结构.
记得在app.module.ts中声明你的组件然后你可以使用它,比如在app.component.html中,就像在示例中一样,data-table-demo-1是你的组件,其中包含表:
<div style="padding: 25px"> <data-table-demo-1></data-table-demo-1> </div>
编辑:您还必须导入数据表模块,如下所示:
从’angular-2-data-table’导入{DataTableModule}; //或angular-4-data-table
那么app.module.ts可能看起来像这样:
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { TableComponent } from './table/table.component'; import { DataTableModule } from 'angular-4-data-table'; // notice this @NgModule({ declarations: [ AppComponent,TableComponent ],imports: [ BrowserModule,DataTableModule // notice this one ],bootstrap: [AppComponent] }) export class AppModule { }