question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Table is generating only by static data but not by dynamically as per the service response data

See original GitHub issue

if i pass table data as statically like below then only my table is showing rows constructor(public service:ViewListCustomerServiceService) { this.data=[ { id:1, “name”:“Customer 1”, “details”:“Customer 1”, “active”:false }, { “id”:2, “name”:“Customer 2”, “details”:“Customer 2 details goes here”, “active”:false }]; }

but if i assign data from service responded data then i am getting error at browser console as

main.bundle.js:50104EXCEPTION: Error in ./ViewListCustomersComponent class ViewListCustomersComponent - inline template:70:100 caused by: ‘undefined’ is not a function (evaluating ‘source.setPaging(1, this.getSetting(‘pager.perPage’), false)’) main.bundle.js:50106ORIGINAL EXCEPTION: ‘undefined’ is not a function (evaluating ‘source.setPaging(1, this.getSetting(‘pager.perPage’), false)’) main.bundle.js:50113ERROR CONTEXT: main.bundle.js:50114 DebugContext main.bundle.js:108412 ViewWrappedError

Here is my constructor in component constructor(public service:ViewListCustomerServiceService) { this.service.getCustomerItemList().then(lst =>this.data=(lst)); }

Here is my service @Injectable() export class ViewListCustomerServiceService {

constructor(private http:Http) { }

getCustomerItemList():Observable<CustomerDetailsItem[]> { let response = this.http.get(`${AppSettings.BACK_ENDPOINT}/list-customers); let customerDetailItems = response.map(mapCustomerItems).toPromise(); return customerDetailItems; } }

function mapCustomerItems(response:Response):CustomerDetailsItem[] { let customerDetailsItem =response.json().map(toCustomerItem); return customerDetailsItem; }

function toCustomerItem(r:any):CustomerDetailsItem { let customerDetailItem = <CustomerDetailsItem>({ id:r.id, name:r.name, details:r.details, active:r.active, }); return customerDetailItem; }

if i print my service response to console then i am getting array of Objects eg. [Object, Object]

i also searched about this issue then found that before response coming from Service then component is calling. please suggest me about this issue.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

5reactions
Geoidecommented, Feb 24, 2017

I think you can try something like this:

import { LocalDataSource } from 'ng2-smart-table';
data: LocalDataSource;
...
constructor(public service:ViewListCustomerServiceService) {
this.service.getCustomerItemList().then(this.data = new LocalDataSource(lst););
}
1reaction
dragoplutcommented, Feb 23, 2017

Confirm. Have same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mysql - dynamic or static database tables
Should I create a new session table dynamically or a one table with the col sessionId where I store the data from all...
Read more >
How to Convert a Static HTML Table to a Dynamic JavaScript ...
Convert the HTML Table to a Data Grid to allow sorting, filtering and pagination. How to Render Data with HTML Tables. The first...
Read more >
Static Data vs. Dynamic Data: Why Companies Must Transition
We explore the difference between static data and dynamic data and covers why this transition is critical to the success of modern business....
Read more >
How to add data dynamically to mat-table dataSource?
I have found a solution for this problem, basically if you do: this.dataSource.data.push(newElement); //Doesn't work. But if you replace the ...
Read more >
Defining static or dynamic data - IBM
The API value mapping depends on the dynamic data root node that you select. Rows in the table component are derived from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found