我在下一张表中使用了材料。
我有三个组成部分:
在EnhancedTableHead
中,我映射列并显示每个TableCell
的标签。
我需要从孩子onClick
调用EnhancedHead
来致电EnhancedTable
的{{1}}。
EnhancedTable
handleRequestSort
表
const EnhancedTableHead = props => {
const {columns, onSelectAllClick, order, numSelected, totalCount, onRequestSort } = props
let createSortHandler = property => event => onRequestSort(event, property)
return (
<TableHead>
<TableRow>
{columns && <TableCell checkbox>
<Checkbox
checked={numSelected === totalCount && numSelected }
onCheck={onSelectAllClick}
/>
</TableCell>}
{columns && columns.map(({key, label, sortable}) =>
<TableCell
key={key}
>
<TableSortLabel
active={order === key}
direction={order}
onClick={createSortHandler(key)}
>
{label}
</TableSortLabel>
</TableCell>
)}
</TableRow>
</TableHead>
)
}
EnhancedTable
const Table = props => {
const {data, columns, children, selectable, order, selected, onSelect, onDelete, onSearch, onDuplicate, onSort, search} = props
return (
<div>
{selectable &&
<EnhancedTableToolbar
numSelected={selected.length}
handleSearch={() => onSearch(data)}
value={search}
unselectSelected={() => onSelect([])}
deleteSelected={() => onDelete(selected)}
duplicateSelected={() => onDuplicate([...data, ...selected], [selected])}
/> }
<MuiTable >
{selectable
? <EnhancedTableHead
columns={columns}
numSelected={selected.length}
order={order}
totalCount={data.length}
onSelectAllClick={() => onSelect( selected.length === data.length ? []: data )}
onRequestSort={property => event => onSort(event, property)}
/>
: <TableHead>
<TableRow >
{columns.map(({label}) =>
<TableCell>
{label}
</TableCell>)}
</TableRow>
</TableHead>
}
.....
答案 0 :(得分:0)
<强> EnhancedTable 强> 键入它的列键,
onClick={() => onRequestSort(key)}
表格强> onRequestSort(来自EnhancedTable的道具)
onRequestSort={key => onSort(key)}
<强> EnhancedTable 强>
handleRequestSort = key => {...}
onSort={this.handleRequestSort}