How to hide column in Ag Grid?

Nikul Vyas picture Nikul Vyas · Jul 13, 2018 · Viewed 9.2k times · Source

I am fetching data from a database and filling it by adding a manual action button column into Ag-Grid. Now, the first columns consist of those action buttons and 2nd column contains _id I want to hide that second column but in ag-grid documentation they gave information only about hiding column on static data. Here's my code that has column def.

setMasterData (state, payload) {
if (!payload) {
  state.tableData.rows = [];
} else {
  // First column holds the buttons to delete the row item
  let cols = [{
    field: '',
    headerName: 'Actions',
    width: 200,
    colId: 'params',
    cellRendererFramework: 'gridEditButtons'
  }];
  cols = cols.concat(Object.keys(payload[0]).map(x => {
    return {
      field: x,
      headerName: x.replace(/([A-Z])/g, ' $1').replace(/^./, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); })
    };
  }));
  state.tableData.cols = cols;
  state.tableData.rows = payload;
 }
}

How to hide the next column following action column?

Answer

Aslam picture Aslam · Jul 17, 2018
 ...gridColumnApi.setColumnVisible('name of column', false);

One way is to switch off the visibility based on the name of the column.