DataTable component for Angular2 framework
npm install angular2-datatable-pagination
npm i -S angular2-datatable-pagination
`
Usage example
AppModule.ts
`typescript
import {NgModule} from "@angular/core";
...
import {NG2DataTableModule} from "angular2-datatable-pagination";
@NgModule({
imports: [
...
NG2DataTableModule
],
...
})
export class AppModule {
}
`
server pagination
`html
[mfIsServerPagination]="true"
`
UserComponent.html
`html
[(mfSortBy)]="sortBy" [(mfSortOrder)]="sortOrder" [mfActivePage]="activePage" (mfOnPageChange)="onPageChange($event)"
[mfIsServerPagination]="true" [(mfAmountOfRows)]="itemsTotal" (mfSortOrderChange)="onSortOrder($event)">
Name
Email
Age
City
{{item.name}}
{{item.email}}
{{item.age}}
{{item.city | uppercase}}
`
UserComponent.ts
`typescript
ngOnInit(): void {
this.loadData();
}
public loadData() {
this.http.get("/app/data.json")
.subscribe((data) => {
setTimeout(() => {
this.data = _.orderBy(data.json(), this.sortBy, [this.sortOrder]);
this.data = _.slice(this.data, (this.activePage-1)this.rowsOnPage, (this.activePage-1)this.rowsOnPage + this.rowsOnPage);
this.itemsTotal = data.json().length;
}, 2000);
});
}
public toInt(num: string) {
return +num;
}
public sortByWordLength = (a: any) => {
return a.city.length;
}
public remove(item) {
let index = this.data.indexOf(item);
if (index > -1) {
this.data.splice(index, 1);
}
}
public onPageChange(event) {
this.rowsOnPage = event.rowsOnPage;
this.activePage = event.activePage;
this.loadData();
}
public onSortOrder(event) {
this.loadData();
}
`
client pagination user angualr2-datatable
but you need
`typescript
import {NG2DataTableModule} from "angular2-datatable-pagination";
`
API
$3
- selector: table[mfData]
- exportAs: mfDataTable
- inputs
- mfData: any[] - array of data to display in table
- mfRowsOnPage: number - number of rows should be displayed on page (default: 1000)
- mfActivePage: number - page number (default: 1)
- mfSortBy: any - sort by parameter
- mfSortOrder: string - sort order parameter, "asc" or "desc"
- mfIsServerPagination: boolean -default value false
- outputs
- mfSortByChange: any - sort by parameter
- mfSortOrderChange: any - sort order parameter
- mfOnPageChange: any - page change parameter(rowsOnPage,activePage)
$3
- selector: mfDefaultSorter
- inputs
- by: any - specify how to sort data (argument for lodash function _.sortBy )
$3
Displays buttons for changing current page and number of displayed rows using bootstrap template (css for bootstrap is required). If array length is smaller than current displayed rows on page then it doesn't show button for changing page. If array length is smaller than min value rowsOnPage then it doesn't show any buttons.
- selector: mfBootstrapPaginator
- inputs
- rowsOnPageSet: number` - specify values for buttons to change number of diplayed rows