In ag-grid
, when I want to retrieve the row index I use:
params.node.id
However, I couldn't find a way to do the same for columns.
All that I found is retrieve the columnId
which refers to the field variable in the column definition.
I.e: If this is the column definition:
{
headerName: "checkButton 2",
field: "checkbuttonTwo",
cellRenderer: "checkButtonComponent",
width: 150
}
This:
params.column.getId()
Would return:
checkbuttonTwo
So my question is:
Is there any way to retrieve the column index?
For example: For the second column I would have 2 and so on and so forth.
Thank you
I wrote a helper function in TypeScript for getting the column index by col id.
function getColumnIndexByColId(api: ColumnApi, colId: string): number {
return api.getAllColumns().findIndex(col => col.getColId() === colId);
}
There is no direct way to get the column index, however you can use the getAllColumns()
method on Column API
to get all columns and then find the index of your column from that array.
More info on Column API
here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With