简体   繁体   English

在 Ag-grid 中编辑标题

[英]Edit headers in Ag-grid

Ag-grid gives support to edit column cells. Ag-grid 支持编辑列单元格。 How do I edit column headers in ag-grid?如何在 ag-grid 中编辑列标题?

It's there on documentations itself.它在文档本身上。 Link: Updating Column Definitions链接: 更新列定义

After the grid has been initialised it may be necessary to update the column definition.网格初始化后,可能需要更新列定义。 It is important to understand that when a column is created it is assigned a copy of the column definition defined in the GridOptions.重要的是要了解,在创建列时,会为其分配 GridOptions 中定义的列定义的副本。 For this reason it is necessary to obtain the column definition directly from the column.因此,有必要直接从列中获取列定义。

The following example shows how to update a column header name after the grid has been initialised.以下示例显示如何在初始化网格后更新列标题名称。 As we want to update the header name immediately we explicitly invoke refreshHeader() via the Grid API.由于我们想立即更新标题名称,因此我们通过 Grid API 显式调用 refreshHeader()。

 // get a reference to the column var col = gridOptions.columnApi.getColumn("colId"); // obtain the column definition from the column var colDef = col.getColDef(); // update the header name colDef.headerName = "New Header"; // the column is now updated. to reflect the header change, get the grid refresh the header gridOptions.api.refreshHeader();

A. Set header before init: A. 在 init 之前设置标头:

var columnDefinition = [{headerName: 'yourHeaderName', field:'fieldNameFromDataSource'}]//define
gridOptions = {columnDefs: columnDefinition}

B. Change header after rendered: B. 渲染后更改标题:

var col = gridOptions.columnApi.getColumn('fieldName');
var colDef = col.getColDef();
colDef.headerName = 'newHeaderName';
gridOptions.api.refreshHeader();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM