简体   繁体   English

ag-grid 将列标题设置为复选框,并进行全选或取消全选列,而不是仅组

[英]ag-grid set the column header to be a checkbox,and do the select all or deselect all column,other than only groups

使用 ag-grid 时,我想将第一列标题设置为复选框,并对除组以外的所有行执行全选或取消全选列操作。

In gridOptions: 在gridOptions中:

angularCompileHeaders: true

Where you are defining your columns, define the first column as such: 在定义列的位置,如下定义第一列:

{
   field: 'RowSelect',
   headerName: ' ',
   checkboxSelection: true,
   suppressMenu: true,
   suppressSorting: true,
   headerCellRenderer: selectAllRenderer
 },

In that file define the renderer: 在该文件中定义渲染器:

function selectAllRenderer(params) {
    var cb = document.createElement('input');
    cb.setAttribute('type', 'checkbox');

    var eHeader = document.createElement('label');
    var eTitle = document.createTextNode(params.colDef.headerName);
    eHeader.appendChild(cb);
    eHeader.appendChild(eTitle);

    cb.addEventListener('change', function (e) {
        if ($(this)[0].checked) {
            params.api.selectAll();
        } else {
            params.api.deselectAll();
        } 
    });
    return eHeader; 
}

Please note that the creator is currently working on making this a feature, but this is the current work-around. 请注意,创建者当前正在努力使其成为一项功能,但这是当前的解决方法。 Check here for updates and a more generic non-angular version: selectAll Feature Discussion 在此处查看更新和更通用的非角度版本: selectAll功能讨论

Should anyone come here looking for answers this feature is already in ag-grid, just place headerCheckboxSelection: true in your column's definition.如果有人来这里寻找答案,此功能已经在 ag-grid 中,只需将headerCheckboxSelection: true放在您的列定义中。

See docs here 在此处查看文档

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

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