Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ag-grid setColumnVisible not working

Tags:

ag-grid

Is there something else I need to do to ensure gridOptions.columnApi.setColumnVisible does what it says on the tin? :-

This code is running at runtime on a rendered grid and should just hide the column instantly, but does nothing:-

gridOptions.columnApi.setColumnVisible("the col name", false);
like image 385
Hugh Gallagher Avatar asked Feb 05 '23 01:02

Hugh Gallagher


1 Answers

Two possible causes of this:

  • The grid isn't ready when you attempt to hide the column. This probably isn't the case as you say the grid has been rendered, but it's worth checking
  • You're not using correct column identifier. This can be either a column id or Column object.

It's probably the latter - are you perhaps using the header name instead of the field/col id?

For example, if you have this:

var columnDefs = [
    {headerName: "Athlete", field: "athlete", width: 200}
];

Then the first parameter would be 'athlete', not 'Athlete'.

You can additionally specify a colId to rule out any conflicts and then use this id in your api call:

var columnDefs = [
    {headerName: "Athlete", field: "athlete", width: 200, colId: "athleteCol"}
];

But this isn't normally necessary.

like image 112
Sean Landsman Avatar answered Feb 08 '23 22:02

Sean Landsman