Angular Data Table
Angular Data Table
l-lin / angular-datatables
Dismiss
Join GitHub today
GitHub is home to over 40 million developers working together to host and
review code, manage projects, and build software together.
Sign up
No one assigned
I'm submitting a...
Labels
Angular
[ ] Regression (a behavior that used to work and stopped working in a new release) question
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
Projects
None yet
No milestone
Current behavior
When I load the datatable the first time, everything works propertly, but if I add / edit or delete a new row
using http, the data changes but the table doesn't recognize it. For example, If the table is empty it
shows "No data available in table", after I push a new row to my array, I can see the row but also the "no
data available" message,in the footer still displays "showing 0 to 0 of 0 entries" and I can't use the
search bar to find the new row because it says no results. I tried using the rerender method as shown in
the documentation, but after the rerender the new data disappear.
Expected behavior
https://github.com/l-lin/angular-datatables/issues/1146 1/6
21/08/2019 Angular 4 - Datatable isn't reloading data correctly. · Issue #1146 · l-lin/angular-datatables · GitHub
The table should recognize the changes made to the data in the table.
This is my component
Template
https://github.com/l-lin/angular-datatables/issues/1146 2/6
21/08/2019 Angular 4 - Datatable isn't reloading data correctly. · Issue #1146 · l-lin/angular-datatables · GitHub
</tbody>
</table>
iCrash91 changed the title Datatable isn't reloading data correctly. Angular 4 - Datatable isn't
reloading data correctly. on 1 Dec 2017
Angular and DataTables do not work on the same "data", ie any changes on Angular won't be impacted
on DataTables. After you add your row, you need to rerender your DataTable so that DataTables
acknowledges the changes.
Unfortunately, it's not really smooth and performant as it will rerender the whole DataTables instead of
just adding/removing rows... I don't have any alternative solution.
this is a problem for our project, many tables need to play with dynamic data, so we decided to stop
using this. the glitch it's making while rerendering is not a good user experience.
Another approach is to not use the angular renderer, but using the DataTable's API to add rows. This
way, your table will be fully updated.
you will need to destroy your datatable before you run this.dtTrigger.next(); when data is updated ->
update: i use it this way in my application works just fine when rows added or deleted the it will rerender
table as written in above comments not that "beautiful" experience..
i have many datable in my component and i need to specify the one that is dynamic
https://github.com/l-lin/angular-datatables/issues/1146 3/6
21/08/2019 Angular 4 - Datatable isn't reloading data correctly. · Issue #1146 · l-lin/angular-datatables · GitHub
i don't really know how to build up a project for Angular5 + Datatables in plunkr sorry but here is the
code
HTML
<tbody>
<tr *ngFor="let lacune of lacunes" class="table-row-clickable"
(click)="voirLacune(lacune)">
<td>{{lacune.numero}}</td>
<td [innerHTML]="lacune.description"></td>
</tr>
</tbody>
</table>
Component
ngOnInit(): void {
this.route.params.subscribe(params => {
forkJoin(
this.appreciationsService.obtenirListe(),
this.recommandationsService.obtenir(+params['id'])
).subscribe(reponse => {
this.recommandation = reponse[1];
this.lacunes = this.recommandation.lacunes;
this.trigger.next(); // This doesnt render the datatables nor does it show
sort arrow on table and it doesnt add datatables class to the table
});
});
}
ngAfterViewInit doesn't work for us, because we are loading data async and the AfterViewInit were
called before data were back from server.
the this.trigger.next) in ngOnInit doesn't work either, while debugging the datables pluggin doesnt
receive the next() event.
setTimeout(function() {
this.trigger.next();
}.bind(this));
For information, you can use this plnkr template to demonstrate your issue.
https://github.com/l-lin/angular-datatables/issues/1146 4/6
21/08/2019 Angular 4 - Datatable isn't reloading data correctly. · Issue #1146 · l-lin/angular-datatables · GitHub
I'm kind of confused. So what this library actually does "in Angular way"? It seems like nothing else than
a glorified wrapper over DataTable's API, but what's the point if it cannot properly rerender the data
angular ngFor is generating? That destroy/create technique is hack at best. Is there no other way?
it seems that the original library is using the same way to regenerate the data if you dont use the column
data way.
It seems like nothing else than a glorified wrapper over DataTable's API
what's the point if it cannot properly rerender the data angular ngFor is generating? That
destroy/create technique is hack at best.
Unfortunately, it's been quite a time since I "touched" the frontend development (because it's moving so
fast and it's not really my "expertise" and I don't have much time this year), that's why there are no
improvement in this wrapper for quite some time... But, pull requests are always welcome :)
And you can check the code it's pretty straight forward.
i'm also having the same problem, reloading the data is not binding properly.
Its disappeared immediately
if it can be used only with static data then it should be given with big heading on front page of it
@ViewChild(DataTableDirective)
dtElement: DataTableDirective;
differ: any;
first: Boolean = true;
https://github.com/l-lin/angular-datatables/issues/1146 5/6
21/08/2019 Angular 4 - Datatable isn't reloading data correctly. · Issue #1146 · l-lin/angular-datatables · GitHub
ngDoCheck() {
const change = this.differ.diff(this.rows);
if (change && !this.first) {
this.rerender();
}
this.first = false;
}
ngAfterViewInit(): void {
this.dtTrigger.next();
}
ngOnDestroy(): void {
this.dtTrigger.unsubscribe();
}
rerender(): void {
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
// Destroy the table first
dtInstance.destroy();
// Call the dtTrigger to rerender again
// this.dtTrigger.next();
});
}
It is weird because if i dont destroy the datatable the row shows, but i cant search or use the datatable
but when i destroy it it the destroy the new data and change it to where the datatable was initialized.
rerender(): void {
setTimeout(() => {
// put rest of the code here
});
}
@pktron np ;) it doesn't solve all the problem but it help in 95% of the case !
https://github.com/l-lin/angular-datatables/issues/1146 6/6