Creating A Table Based On Json/object Javascript
Hi I want to create a table(school timetable) based on a dummydata which is in json object format. The object looks like below. this._days=[ { 'day': '',
Solution 1:
you can use primeng datatable in angular 2.
In your module use
import {DataTableModule,SharedModule} from'primeng/primeng';
In HTML give
<p-dataTable [value]="cars"><p-columnfield="vin"header="Vin"></p-column><p-columnfield="year"header="Year"></p-column><p-columnfield="brand"header="Brand"></p-column><p-columnfield="color"header="Color"></p-column></p-dataTable>
in component
publiccars: Car[];
constructor(private http: Http) { }
ngOnInit() {
this.http.get('data.json')
.map(res => res.json())
.subscribe(data =>this.cars = data,
err =>console.log(err),
() =>console.log('Completed'));
}
}
You may make use of PrimeNG datatable in Angular2 https://www.primefaces.org/primeng/#/datatable
Post a Comment for "Creating A Table Based On Json/object Javascript"