Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

primeNG Datatable does not update when datasource changes

I have an issue with primeNG datatable, when updating the datasouce the datatable does not automatically update. I have two datatables in different components that are communicating via a service, when clicking on one row in the first datatable a method is called which updates the datasource, however the second datatable does not recognize it. Maybe someone had a similar issue or has an example of how to solve issues like that with primeNG datatable? I would appreciate any help.

like image 290
Memuva Avatar asked Jan 23 '26 22:01

Memuva


1 Answers

in my case:push data into tableData array, then copy tableData array itself (use slice())

export class DataTableComponent{
    tableData=[];
    county={id:1,name:"china"}
    onAdd(){
         this.tableData.push( Object.assign({}, this.country));
         this.tableData=this.tableData.slice();
    }
}

and it works

like image 141
Anne Avatar answered Jan 26 '26 13:01

Anne