beingyogi
beingyogi

Reputation: 1416

Aggrid get get name of columns displayed in the table

I am using vue aggrid. I have 10 columns in the table and all columns are displayed by default. Now the user can select and unselect column from the column panel. Is there a way to get an array of columns which are selected by the user that are displayed in the table. I tried

this.gridOptions.api.sortController.columnController.getAllDisplayedColumns()

This gives the array of objects of selected columns, but is there any other way through which we can get the selected columns names.

Upvotes: 2

Views: 7958

Answers (2)

sandeep joshi
sandeep joshi

Reputation: 2151

If I understood your question correctly then you are looking for array containing name(display label or columnId) of the columns like

    ["column1","column2","column3",...].

well you are already on the right track using getAllDisplayedColumns method which gives you all the columns displayed in the grid. You can use below method to get the list/array of column names which are rendered in the grid and are visible.

    var columnNames = gridOptions.api.columnController.getAllDisplayedColumns().map(function (col) { return col.getColId(); })

Upvotes: 1

NearHuscarl
NearHuscarl

Reputation: 81555

You can get all visible columns by calling that function in your question directly from the ColumnAPI

columnApi.getAllDisplayedColumns()

Upvotes: 3

Related Questions