Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing onRowsDelete in customToolbarSelect #1708

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/customize-toolbarselect/CustomToolbarSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Tooltip from "@mui/material/Tooltip";
import CompareArrowsIcon from "@mui/icons-material/CompareArrows";
import IndeterminateCheckBoxIcon from "@mui/icons-material/IndeterminateCheckBox";
import BlockIcon from "@mui/icons-material/Block";
import DeleteIcon from '@mui/icons-material/Delete';
import { withStyles } from "tss-react/mui";

const defaultToolbarSelectStyles = {
Expand Down Expand Up @@ -38,6 +39,10 @@ class CustomToolbarSelect extends React.Component {
console.log(`block users with dataIndexes: ${this.props.selectedRows.data.map(row => row.dataIndex)}`);
};

handleDelete = () => {
this.props.onRowsDelete();
};

render() {
const { classes } = this.props;

Expand All @@ -58,6 +63,11 @@ class CustomToolbarSelect extends React.Component {
<BlockIcon className={classes.icon} />
</IconButton>
</Tooltip>
<Tooltip title={"Delete selected"}>
<IconButton className={classes.iconButton} onClick={this.handleDelete}>
<DeleteIcon className={classes.icon} />
</IconButton>
</Tooltip>
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/customize-toolbarselect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function Example() {
responsive: "vertical",
rowsPerPage: 10,
selectToolbarPlacement: stp,
customToolbarSelect: (selectedRows, displayData, setSelectedRows) => (
<CustomToolbarSelect selectedRows={selectedRows} displayData={displayData} setSelectedRows={setSelectedRows} />
customToolbarSelect: (selectedRows, displayData, setSelectedRows, onRowsDelete) => (
<CustomToolbarSelect selectedRows={selectedRows} displayData={displayData} setSelectedRows={setSelectedRows} onRowsDelete={onRowsDelete} />
),
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/TableToolbarSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class TableToolbarSelect extends React.Component {
</Typography>
</div>
{options.customToolbarSelect ? (
options.customToolbarSelect(selectedRows, displayData, this.handleCustomSelectedRows)
options.customToolbarSelect(selectedRows, displayData, this.handleCustomSelectedRows, onRowsDelete)
) : (
<Tooltip title={textLabels.delete}>
<IconButton className={classes.iconButton} onClick={onRowsDelete} aria-label={textLabels.deleteAria}>
Expand Down
4 changes: 2 additions & 2 deletions test/MUIDataTableToolbarSelect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('<TableToolbarSelect />', function() {
assert.strictEqual(actualResult.length, 1);
});

it('should call customToolbarSelect with 3 arguments', () => {
it('should call customToolbarSelect with 4 arguments', () => {
const onRowsDelete = () => {};
const customToolbarSelect = spy();
const selectedRows = { data: [1] };
Expand All @@ -38,7 +38,7 @@ describe('<TableToolbarSelect />', function() {
/>,
);

assert.strictEqual(customToolbarSelect.calledWith(selectedRows, displayData, match.typeOf('function')), true);
assert.strictEqual(customToolbarSelect.calledWith(selectedRows, displayData, match.typeOf('function'), match.typeOf('function')), true);
});

it('should throw TypeError if selectedRows is not an array of numbers', done => {
Expand Down