Home > Software engineering >  Setting Column Visibility in AgGrid React
Setting Column Visibility in AgGrid React

Time:02-16

I have a BE that returns an Array of objects (columns) in React. The objects are structured like this {headerName: 'string', field: 'string', visible: boolean}. The visible parameter doesn't actually do anything as the column will always be visible. I know in AgGrid the Column Object has a visible parameter which if changed shows or hides the column. How can I make AgGrid use the visible parameter the backend gives me? Am I using the wrong strategy here? How would you do it? As far as changing the object returned by the backend and AgGrid settings.

CodePudding user response:

To hide/show a column in AG Grid, you have to set the hide property on the column: enter image description here

Since your server is returning visibility, I would suggest either of the two approaches:

  1. On the client side - Add a function to modify the data returned from the server, such that visibility is renamed to hide
  1. On the server side - the response object for the data should have the hide property

CodePudding user response:

use useMemo and recreate the columnDefs when needed:

Demo

  • Related