ggmod / angular-2-data-table-demo

Demo application and examples for the Angular 2 data table (https://github.com/ggmod/angular-2-data-table)
MIT License
29 stars 97 forks source link

how to pass data from api to angular-2-data-table #3

Open vardhineedik opened 7 years ago

vardhineedik commented 7 years ago

Hi all,

below is my result JSON from api. how to bind this data to Datatable please help me .

[{"Building":"B85","DeviceID":"402072","PumpNo":3,"EventDateTime":"2017-01-30T23:16:00"},{"Building":"B85","DeviceID":"402072","PumpNo":6,"EventDateTime":"2017-01-30T23:17:00"},{"Building":"B85","DeviceID":"402072","PumpNo":7,"EventDateTime":"2017-01-30T23:17:00"},{"Building":"B85","DeviceID":"402072","PumpNo":8,"EventDateTime":"2017-01-30T23:09:00"}]

codingpajamas commented 7 years ago

did you solve this? I have the same issue right now.

bofcarbon1 commented 7 years ago

in DEMO1

itemResource = new DataTableResource(persons);

The only example I see uses a hard coded Json string array 'persons' that is assigned when the itemResource object is created. I don't understand why 'DataTablResource' which seems like it is the import for the tool component would have a dependency on local data.

I am pulling my table data content from an observable that has a callback that parses the Json data returned and converts it to a object that I can use in an ngfor loop. So i'm not sure how that converts to using the data table here but i got stuck with this. I should be swapping the persons object for my converted object but I am getting a typescript error telling me that itemResource is undefined.

Seems like I can only use this Data Table 2 if create an object with data before I actually get that data in my ngInit function.

ddurette commented 6 years ago

You need to this with your JSON results:

this.resultsResource = new DataTableResource(this.results);

That's what I do and it works.

asad11111 commented 6 years ago

@bofcarbon1 did u resolve this issue. I'm stuck