I am trying to track onSortChanged and get the Column info from that sort change event so that I can store that column and its direction of sort in the database.
I am having trouble getting the info from the onSortChanged event though, and I feel like I must not understand exactly what I should be accessing from it?
This is my code:
in gridOptions:
defaultColDef: {
floatingFilter: true,
filter: 'agTextColumnFilter',
filterParams: {
applyMiniFilterWhileTyping: true,
},
resizable: true,
cellStyle: function (params) {
return {'font-size': '14px'};
},
width: 120,
sortable: true,
sortingOrder: ['desc', 'asc', null],
},
rowData: this.invoiceList[0].invoiceList,
rowDragManaged: false,
animateRows: true,
components: {
invoiceCellRenderer: InvoiceCellRenderer
},
onSelectionChanged: (event) => this.selectionChanged(event),
onSortChanged: (params) => this.sortChanged(params),
}
on sort changed function:
sortChanged(event)
{
console.log('event', event);
var column = event.api.getColId;
var col = event.columnApi.getColumn();
console.log('invoicelist api', this.invoiceListGridApi);
var sort = this.invoiceListGridApi.getSortModel();
console.log('1', this.invoiceListColumnDefinitions);
console.log('2', sort);
console.log('3', col);
console.log('column', event.api);
}
All my attempts to access the colId or to getColDef is undefined.
If I try to get access to the api of the invoiceListGridOptions or the api of the invoiceListColumnDefinitions, that is also undefined.
I don’t know what I’m doing wrong?
Any tips would be appreciated.