akveo / akveo/ng2-smart-table

Table only populates when clicking on sort field

未关闭
#53 10 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
1.6k
派生
867
PR 合并指标
30 天内没有已合并 PR

描述

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:

`





``

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。