我有以下代码
import React from 'react'
import Button from '@material-ui/core/Button';
import Checkbox from '@material-ui/core/Checkbox';
import { DataGrid } from '@material-ui/data-grid';
export default function CheckBoxTable(props) {
const inputs = ['Input 1 ','Input 2','Input 3'];
const outputs= ['Output 1', 'Output 2', 'Output 3', 'Output 4'];
const rows = outputs.map((output,index) => ({id:index, optionName:output}));
const headers = [{ field: 'optionName', headerName: '', width: 150 }];
const col_inputs = inputs.map((input,index) => ( {field: input, headerName: input, width: 160, renderCell: (params) => {return (<Checkbox name={index} onChange={handleCheckboxClick} inputProps={{ 'aria-label': 'primary checkbox' }}/>)}} ))
const columns = headers.concat(col_inputs)
const handleCheckboxClick = (e) => {
console.log("Checkbox clicked " + e.target.name)
}
return (
<div>
<div style={{ height: 500, width: '100%' }} >
<DataGrid rows={rows} columns={columns} />
</div>
<div>
{/* Some other component
</div>
</div>
)
}
我试图创建的是一个复选框表。我可以获取选中复选框的列,但如何获取选中复选框的行?
1条答案
按热度按时间u3r8eeie1#
Get row item on checkbox Selection in React Material-UI DataGrid
这是你要找的吗?可以向onRowSelected传递回调