From 989162f960d8295028a2d285cc5ee440e6ca1e6e Mon Sep 17 00:00:00 2001 From: Aleks Date: Mon, 3 May 2021 01:23:52 -1000 Subject: [PATCH] Fixing https://github.com/gregnb/mui-datatables/issues/544 by exposing the onRowsDelete function to customToolbarSelect which can be used to delete rows in the table --- .../customize-toolbarselect/CustomToolbarSelect.js | 10 ++++++++++ examples/customize-toolbarselect/index.js | 4 ++-- src/components/TableToolbarSelect.js | 2 +- test/MUIDataTableToolbarSelect.test.js | 4 ++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/customize-toolbarselect/CustomToolbarSelect.js b/examples/customize-toolbarselect/CustomToolbarSelect.js index a05f3131e..bd928eb88 100644 --- a/examples/customize-toolbarselect/CustomToolbarSelect.js +++ b/examples/customize-toolbarselect/CustomToolbarSelect.js @@ -5,6 +5,7 @@ import CompareArrowsIcon from "@material-ui/icons/CompareArrows"; import IndeterminateCheckBoxIcon from "@material-ui/icons/IndeterminateCheckBox"; import BlockIcon from "@material-ui/icons/Block"; import { withStyles } from "@material-ui/core/styles"; +import DeleteIcon from '@material-ui/icons/Delete'; const defaultToolbarSelectStyles = { iconButton: { @@ -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; @@ -58,6 +63,11 @@ class CustomToolbarSelect extends React.Component { + + + + + ); } diff --git a/examples/customize-toolbarselect/index.js b/examples/customize-toolbarselect/index.js index 4727d3571..446e4e2b3 100644 --- a/examples/customize-toolbarselect/index.js +++ b/examples/customize-toolbarselect/index.js @@ -55,8 +55,8 @@ function Example() { responsive: "vertical", rowsPerPage: 10, selectToolbarPlacement: stp, - customToolbarSelect: (selectedRows, displayData, setSelectedRows) => ( - + customToolbarSelect: (selectedRows, displayData, setSelectedRows, onRowsDelete) => ( + ), }; diff --git a/src/components/TableToolbarSelect.js b/src/components/TableToolbarSelect.js index 8a4fd02c5..2c7a7cd8a 100644 --- a/src/components/TableToolbarSelect.js +++ b/src/components/TableToolbarSelect.js @@ -75,7 +75,7 @@ class TableToolbarSelect extends React.Component { {options.customToolbarSelect ? ( - options.customToolbarSelect(selectedRows, displayData, this.handleCustomSelectedRows) + options.customToolbarSelect(selectedRows, displayData, this.handleCustomSelectedRows, onRowsDelete) ) : ( diff --git a/test/MUIDataTableToolbarSelect.test.js b/test/MUIDataTableToolbarSelect.test.js index bb8657547..85551b276 100644 --- a/test/MUIDataTableToolbarSelect.test.js +++ b/test/MUIDataTableToolbarSelect.test.js @@ -23,7 +23,7 @@ describe('', 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] }; @@ -38,7 +38,7 @@ describe('', 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 => {