.dataset must be reset every time data is updated
I have been working on a project that uses ng-table version 1.0.0 for some time now. We began experiencing performance issues on that version, so we upgraded to version 4.0.0. However, this has caused a problem to appear.
Previously, we loaded our table with data from another array in our controller, like:
self.ngTableParams = new NgTableParams({}, {dataset: self.data});
Then, any changes we made to self.data would be perpetuated to the table rows.
Now, however, changes to self.data aren't pushed through every time, and we have to do something like this whenever the data changes:
self.ngTableOptions.settings().dataset = self.data;
self.ngTableOptions.reload();
It seems that the data in the table isn't actually tied to the objects in the dataset anymore, but is instead deep-copied over. I'm wondering if this is expected behavior that changed between versions and we missed in the documentation, or is perhaps a bug.
There is a (passing) test that says that the dataset is not deep-copied: spec
So it would seems it's not the problem you suspect
I'd definitely be interested in what you find to be root cause of the problem...
I know that the issue is really old by since it hasn't been closed and I have the same issue, I'll post here instead of creating a new issue.
I may have a hint about where the issue come from, but my level of javascript knowledge prevent me from understanding it completely (for now at least).
Here's what I got so far :
export default class MyController {
constructor() {
this.tableData = [];
}
$onInit() {
this.tableParams = new NgTableParams({}, {dataset: this.tableData});
// Following console.log return TRUE
console.log(this.tableParams.settings().dataset === this.tableData);
this.loadTable();
}
loadTable() {
// Following console.log return TRUE
console.log(this.tableParams.settings().dataset === this.tableData);
this.myService.listData()
.then(response => {
// Following console.log return FALSE
console.log(this.tableParams.settings().dataset === this.tableData);
});
}
}
@ccrowhurstram if you're still around, may I ask you if you've got any more information about that and how I could handle it ?
EDIT 1 : After some more test, it seems like this.tableParams.settings().dataset doesn't reference the same object anymore once in the resolved promise's "then".
EDIT 2 : I still haven't solve the mystery of the object referenced by this.tableParams.settings().dataset that is not the same outside and inside the promise. But by directly updating this.tableParams.settings().dataset (and removing the one-way data binding on my columns data) it works.