繁体   English   中英

ag-grid react 如何使用复选框处理数据

[英]ag-grid react How to handle data with checkbox

我想在单击复选框时获取数据

我试过使用 onCellClicked 我在单击行时收到 function onCellClick 上的数据

但是当我点击复选框时什么都没有

我应该使用哪些道具?

export const DataTable = ():JSX.Element=> {
  ...
   const header = [
    {
     headerName: 'Select',
     field: 'selectBox',
     headerCheckboxSelection: true,
     headerCheckboxSelectionFilteredOnly: true,
     checkboxSelection: true
   },
   {
    headerName: name,
    field: 'name',
    sortable: true,
    filter: true
   }

   const onCellClick = (e: CellClickedEvent) => {
     const data = e.data
   }

   return (
     <AgGridReact
      columnDefs={header}
      onGridReady={onGridReady}
      rowData={data}
      rowSelection="mutiple"
      animateRows={true}
      suppressRowClickSelection={true}
      rowMultiSelectWithClick={true}
      onCellClicked={onCellClick}
    />
   )
}

在此处输入图像描述

使用onRowSelected而不是onCellClicked

根据文档: https://www.ag-grid.com/react-grid/grid-events/#reference-selection

rowSelected 行被选中或取消选中。

暂无
暂无

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

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