如何在Ag-Grid React的列标题中添加全选复选框?

时间:2020-07-27 15:28:13

标签: reactjs ag-grid ag-grid-react

在Ag Grid中,有一个选项可以将复选框添加到行中以将其选中。可以在columnDefinitions中定义如下:

{
   checkboxSelection: true
}

此复选框被添加到行本身。现在我的问题是,如何在列标题本身中添加全选复选框?

1 个答案:

答案 0 :(得分:1)

您快到了。您所要做的就是按照docs

中的说明添加colDef.headerCheckboxSelection=true

所以会

<AgGridReact
  // needed if you want to select multiple rows. Default is single
  rowSelection="multiple"
  // not required here. Enable this if you only want checkbox selection, and don't want      
  // to also select the row when the row is clicked.
  suppressRowClickSelection
  columnDefs={[{
    field: 'id',
    checkboxSelection: true,
    headerCheckboxSelection: true,},
    ...
  ]}
/>

Live Demo