简体   繁体   English

AG-Grid 标题单元格选择

[英]AG-Grid Header Cell Selection

I am trying to create an AG-grid to assign permissions in which the Header Selection should select all the cells available in that column.我正在尝试创建一个 AG 网格来分配权限,其中标题选择应选择该列中的所有可用单元格。

It should be something like this :它应该是这样的: 在此处输入图片说明

One way is to create the Header using HTML template and Cell-Renderer for the rows.一种方法是使用 HTML 模板和 Cell-Renderer 为行创建标题。

Is there a way I can achieve this using AG-Grid Properties or API?有没有办法使用 AG-Grid 属性或 API 来实现这一点?

There is a Header Checkbox Selection examples in Ag-grid documentation. Ag-grid 文档中有一个标题复选框选择示例。

Header Checkbox Selection标题复选框选择

It is possible to have a checkbox in the header for selection.可以在标题中有一个复选框以供选择。 To configure the column to have checkbox, set colDef.headerCheckboxSelection=true.要将列配置为具有复选框,请设置 colDef.headerCheckboxSelection=true。 headerCheckboxSelection can also be a function, if you want the checkbox to appear sometimes (eg if the columns is ordered first in the grid). headerCheckboxSelection 也可以是一个函数,如果您希望复选框有时出现(例如,如果列在网格中排在第一位)。

// the name column header always has a checkbox in the header
colDef = {
    field: 'name',
    headerCheckboxSelection: true
    ...
}

// the country column header only has checkbox if it is the first column
colDef = {
    field: 'country',
    headerCheckboxSelection: function(params) {
        var displayedColumns = params.columnApi.getAllDisplayedColumns();
        var thisIsFirstColumn = displayedColumns[0] === params.column;
        return thisIsFirstColumn;
    }
    ...
}

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

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