I am trying to use custom sorting on a column in ag-Grid in my Ionic 4/Angular 8 application.
I have a sample application here, or on Stackblitz I can't get it to run on Stackblitz, but it definatley runs locally,
At any rate a couple of things to note are I want the grid to run in virtual mode (eg may have 1000 rows of data), and also I have set this.gridOptions.immutableData = true; to handle my data from ng/rx.
Also I am using a component as a cell template, but I think we can ignore that here (using an existing example)
I wish to have the rows sorted, and so calling my dateComparator function both
- When I first load the data
- If I have any data added or updated
To emulate new data coming in from a server, I have an add button which calls the add method.
I have added a comparator on the column...
public ngAfterViewInit(): void {
const self = this;
this.gridOptions.immutableData = true;
this.gridOptions.animateRows = true
this.gridOptions.api.setColumnDefs([
{
headerName: 'myheader',
comparator: self.dateComparator,
sortable: true,
field: 'equipment',
cellStyle: { padding: 0 },
cellRendererFramework: TemplateRendererComponent,
cellRendererParams: {
ngTemplate: this.itemCard
},
},
]);
this.setData();
}
private dateComparator(valueA, valueB, nodeA, nodeB, isInverted): number {
console.log('sorting');
return 1;
}
However, when I load the grid, or call the above add method, my dateComparator is not being called. It is only called if I click the column header.
I have tried calling this.gridOptions.api.redrawRows() but this does not cause it to sort. I can't see any other obvious sort function to call.
My question is, how can I have this sorting applied automatically without clicking the column header (ie when I load or update my data)?