3

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?

Nikul Vyas
  • 363
  • 3
  • 7
  • 30

2 Answers2

8
 ...gridColumnApi.setColumnVisible('name of column', false);

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

Aslam
  • 9,204
  • 4
  • 35
  • 51
2

Have this attribute on a column definition whichever column you would like to hide.

hide: true

UPDATE

If the code you've provided of map works, then you should be able to achieve this like below.

cols = cols.concat(Object.keys(payload[0]).map(x => {
    return {
      field: x,
      hide: x === '_Id',    // this will be true when your field == '_Id'
      headerName: x.replace(/([A-Z])/g, ' $1').replace(/^./, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); })
    };
  }));

Condition provided for hide will be true for _Id, hence, that column will be hidden.

Paritosh
  • 11,144
  • 5
  • 56
  • 74