Reputation: 942
When I charge datas, the rows shows 0 totals 0 selects, but If I select 1 row then I can see 4 rows 1select, I don't understand why when the application charge doesn't count the rows..
onGridReady(params) {
this.gridApi = params.api;
this.gridColumnApi = params.columnApi;
this.http.get(this.config.getUrl('myProject')).subscribe(data => {
this.columnDefs = data['headers'];
this.rowData = data['datas'];
this.countOnSelectionChanged(); //here
});
params.api.sizeColumnsToFit();
}
I check join the function console.log and totalResults = 0
countOnSelectionChanged() {
console.log('here');
this.selectedResults = this.gridApi.getSelectedRows().length;
this.totalResults = this.gridApi.getDisplayedRowCount();
console.log('totalResults', this.totalResults);
console.log('selectedResults', this.selectedResults);
}
Then when I do click in checkbox
onSelectionChanged() {
this.countOnSelectionChanged();
this.enableAssociatedActions();
}
I call again the function countOnSelectionChanged and now , totalResults = 4.
Thanks.
Upvotes: 0
Views: 3101
Reputation: 393
If I understand you correctly, your problem is that the row count displays '0 totals' directly after you loaded the data.
I think that the api isn't ready i.e. the grid doesn't display the data, when you first call this.gridApi.getDisplayedRowCount()
. You could instead listen for the rowDataChanged
grid event and then call this method.
Documentation:
rowDataChanged
: The client has set new data into the grid using api.setRowData() or changing the rowData bound property.
template:
<ag-grid-angular (rowDataChanged)="countDisplayedRows($event)">
</ag-grid-angular>
ts:
countDisplayedRows(params) {
this.totalResults = params.api.getDisplayedRowCount();
}
Upvotes: 1