I'm creating DataTable in angular js by using following steps
install angular2-datatable from npm
npm i -S angular2-datatable
edit app.module.ts and import the following code
import { DataTableModule } from "angular2-datatable";
Open the app.component.ts file and add the following script
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-daftar-user',
templateUrl: './daftar-user.component.html',
styleUrls: ['./daftar-user.component.css'],
})
export class DaftarUserComponent implements OnInit {
obj: any = new Array({ name: "Sinta", email: "sinta@gmail.com", age: "50" },
{ name: "Jojo", email: "Jojo@gmail.com", age: "15" },
{ name: "Andre", email: "Andre@gmail.com", age: "85" },
{ name: "Simpson", email: "Simpson@gmail.com", age: "45" },
{ name: "Doly", email: "Doly@gmail.com", age: "40" },
{ name: "Bintang", email: "Bintang@gmail.com", age: "36" },
{ name: "Aria", email: "Aria@gmail.com", age: "74" },
{ name: "Sams", email: "Sams@gmail.com", age: "8" },
{ name: "Oly", email: "Oly@gmail.com", age: "12" });
userlist: any;
constructor() {
}
ngOnInit() {
this.userlist = this.obj;
}
}
open the app.component.html file and add the following script
<div class="row margintop20px paddingtopbottom15px whitebackground">
<div class="col-xs-12">
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered " [mfData]="userlist" #mf="mfDataTable" [mfRowsOnPage]="3">
<thead>
<tr>
<th style="width:40px;max-width:40px;">#</th>
<th style="width:60px;max-width:60px;"><mfDefaultSorter by="name">Name</mfDefaultSorter></th>
<th><mfDefaultSorter by="email">Email</mfDefaultSorter></th>
<th><mfDefaultSorter by="age">Age</mfDefaultSorter></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let user of mf.data; let i = index;">
<td scope="row">{{i+1}}</td>
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td>{{user.age}}</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
<mfBootstrapPaginator ></mfBootstrapPaginator>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
I have build a dataTable by using abve code. When I trying to run this code it showing below code
Failed to compile. ./node_modules/rxjs/_esm5/index.js Module build failed: Error: ENOENT: no such file or directory, open '\sample-ng-app\node_modules\rxjs_esm5\index.js'.
I'm not able to figure out the where I went wrong, could you give solution for this issue
EDIT Package.json
{
"name": "sample-ng-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.3",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"angular2-datatable": "^0.6.0",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.3",
"@angular-devkit/build-angular": "~0.6.8",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.8",
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
}