3

我正在从数据库中获取数据并通过将手动操作按钮列添加到 Ag-Grid 来填充它。现在,第一列由那些操作按钮组成,第二列包含 _id 我想隐藏第二列,但在 ag-grid 文档中,他们只提供了关于隐藏静态数据列的信息。这是我的包含 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;
 }
}

如何隐藏操作列之后的下一列?

4

2 回答 2

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

一种方法是根据列的名称关闭可见性。

于 2018-07-17T14:31:31.097 回答
2

在要隐藏的任何列上都有此属性。

hide: true

更新

如果您提供的代码map有效,那么您应该能够实现如下所示。

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(); })
    };
  }));

为 提供的条件hide将为真_Id,因此,该列将被隐藏。

于 2018-07-13T20:37:57.157 回答