akveo / akveo/ng2-smart-table

Table only populates when clicking on sort field

Open
#53 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.6k
Forks
867
PR merge metrics
No merged PRs in 30d

Description

I am pulling data from a database and using angular 2 Observables to subscribe returned records and stored as objects in a local array variable. I implemented http.get() inside a service and subscribed the observable inside my component under ngOnInit(). For some reason the data is only being loaded when I click on a column title (i.e. on sort). Why am I not able to simple load the data?

I get no data found when I go to the webpage:

![smarttable-no data found](https://cloud.githubusercontent.com/assets/4884697/19454932/0fc0523c-9489-11e6-9f66-7218b92fabf3.PNG)

When I click on a field, the data is loaded like so:

![smarttablesedited](https://cloud.githubusercontent.com/assets/4884697/19454954/2385a3e4-9489-11e6-8366-7e938e2d9d83.png)

This is the code inside my component:

```
initData(data) {
this.allUsers = data;
for(var i = 0; i < this.allUsers.data.length; i++) {
if(this.allUsers.data[i].isactive == "true") {
this.allUsers.data[i].isactive = "yes";
} else {
this.allUsers.data[i].isactive = "no";
}
this.users.push({
username: this.allUsers.data[i].username,
firstname: this.allUsers.data[i].firstname,
lastname: this.allUsers.data[i].lastname,
lastloggedin: this.allUsers.data[i].lastloggedin,
isactive: this.allUsers.data[i].isactive
});
}
}

subscribeUsers() {
this._userService.getUsers()
.subscribe(
data => this.initData(data),
error => this.handleError(),
() => {

this.source.load(this.users);
console.log(this.source);
console.log(typeof this.source);
console.log("success");
});
}

ngOnInit() {
this.subscribeUsers();
console.log("show all users");
}
```

This is the code inside my template:

`





``

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.