Since I want to add the action after selection in GridHeader, I am following the tutorial to try to put them together: https://mui.com/x/react-data-grid/selection/#controlled-selection
https://mui.com/x/react-data-grid/column-visibility/#column-visibility-panel I believe this is a very common and universal requirement. When I select a row or rows, I can't pass the resulting data to the GridToolbar subcomponent. It seems that it does not support passing properties. There is example code:
export defualt function App(props: any){
const {rows, columns} = props;
const [selectionModel, setSelectionModel] = useState<GridSelectionModel>([]);
return (
<DataGrid components={{ Toolbar: DataToolbar }}
onSelectionModelChange={(newSelectionModel) => {
setSelectionModel(newSelectionModel);
}}
selectionModel={selectionModel}
{...others} />
);
}
function DataToolbar (){
<GridToolbarContainer>
<Auctions />
<GridToolbarQuickFilter />
<GridToolbarColumnsButton />
<GridToolbarDensitySelector />
</GridToolbarContainer>
}
function Auctions (){
const apiRef = useGridApiContext();
const [selected, setSelected] = useState(false);
const handleSelected: GridEventListener<'rowSelectionCheckboxChange'> = (
params, event, details) => {
//Processing Event
setSelected(!selected);
};
useGridApiEventHandler(apiRef, 'rowSelectionCheckboxChange', handleSelected);
return (
<Fragment>
<IconButton disabled={!selected}><DeleteIcon color={selected? "error" : "disabled"} /></IconButton>
</Fragment>
);
}