Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

angular-6-datatable [Pagination, Sorting in Angular 6]

The “angular-6-datatable” will provide the table component with sorting and pagination for Angular 6. If you want to use the datatable in Angular 6 applications, try the following steps.

Install -
npmi angular-6-datatable--save

The Example -

app.module.ts -
import{ BrowserModule } from'@angular/platform-browser';
import{ NgModule } from'@angular/core';
import{ FormsModule } from'@angular/forms';
import{ RouterModule, Routes} from '@angular/router';

import{ AppComponent } from'./app.component';
import{ UserComponent } from'./user/user.component';
import{ UserListComponent} from './user-list/user-list.component';

import {DataTableModule} from "angular-6-datatable";

@NgModule({
  declarations: [
    AppComponent,
    UserComponent,
    UserListComponent
  ],
  imports: [
    BrowserModule,
    DataTableModule,
    FormsModule,
    RouterModule.forRoot([
      { path: 'user-link', component: UserComponent},
      { path: 'user-list', component: UserListComponent}
    ])
  ],
  providers: [],
  bootstrap: [AppComponent]
})
exportclass AppModule{ }


user-list.component.ts -
import{ Component, OnInit} from '@angular/core';

@Component({
  selector: 'app-user-list',
  templateUrl: './user-list.component.html',
  styleUrls: ['./user-list.component.css']
})
exportclass UserListComponentimplements OnInit{
  public data: any
 
  constructor() {   }

  ngOnInit() {
    this.data= [{'name':'Anil', '[email protected]':'ssd', 'age':'34', 'city':'Noida, UP, India' },
    {'name':'Anil', 'email' :'[email protected]', 'age' :'34', 'city':'Noida'},
    {'name':'Sunil', 'email' :'[email protected]', 'age' :'34', 'city':'Noida'},
    {'name':'Alok', 'email' :'[email protected]', 'age' :'34', 'city':'Noida'},
    {'name':'Tinku', 'email' :'[email protected]', 'age' :'34', 'city':'Noida'},
    {'name':'XYZ', 'email' :'[email protected]', 'age' :'34', 'city':'Noida'},
    {'name':'asas', 'email' :'[email protected]', 'age' :'34', 'city':'Noida'},
    {'name':'erer', 'email' :'[email protected]', 'age' :'34', 'city':'Noida'},
    {'name':'jhjh', 'email' :'[email protected]', 'age' :'34', 'city':'Noida'}
   ]
  }
}


user-list.component.html -

tableclass="table table-striped" [mfData]="data"#mf="mfDataTable"[mfRowsOnPage]="5">
  thead>
  tr>
      th style="width: 20%">
          mfDefaultSorterby="name">UserNamemfDefaultSorter>
      th>
      th style="width: 50%">
          mfDefaultSorterby="email">UserEmailmfDefaultSorter>
      th>
      th style="width: 10%">
          mfDefaultSorterby="age">AgemfDefaultSorter>
      th>
      th style="width: 20%">
          mfDefaultSorterby="city">User CitymfDefaultSorter>
      th>
  tr>
  thead>
  tbody>
  tr *ngFor=


This post first appeared on Programming, please read the originial post: here

Share the post

angular-6-datatable [Pagination, Sorting in Angular 6]

×

Subscribe to Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×