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

Allow async onRowsDelete #835

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Allow async onRowsDelete
  • Loading branch information
pkmnct committed Aug 14, 2019
commit cae21867873bec10eabf859d759541d53e7c3895
22 changes: 12 additions & 10 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import Paper from '@material-ui/core/Paper';
import { withStyles } from '@material-ui/core/styles';
import { buildMap, getCollatorComparator, sortCompare } from './utils';

import MuiTable from '@material-ui/core/Table';
import classnames from 'classnames';
import cloneDeep from 'lodash.clonedeep';
import find from 'lodash.find';
import isUndefined from 'lodash.isundefined';
import merge from 'lodash.merge';
import Paper from '@material-ui/core/Paper';
import PropTypes from 'prop-types';
import React from 'react';
import TableBody from './components/TableBody';
@@ -15,8 +11,13 @@ import TableHead from './components/TableHead';
import TableResize from './components/TableResize';
import TableToolbar from './components/TableToolbar';
import TableToolbarSelect from './components/TableToolbarSelect';
import classnames from 'classnames';
import cloneDeep from 'lodash.clonedeep';
import find from 'lodash.find';
import isUndefined from 'lodash.isundefined';
import merge from 'lodash.merge';
import textLabels from './textLabels';
import { buildMap, getCollatorComparator, sortCompare } from './utils';
import { withStyles } from '@material-ui/core/styles';

const defaultTableStyles = theme => ({
root: {},
@@ -955,14 +956,15 @@ class MUIDataTable extends React.Component {
);
};

selectRowDelete = () => {
selectRowDelete = async () => {
const { selectedRows, data, filterList } = this.state;

const selectedMap = buildMap(selectedRows.data);
const cleanRows = data.filter(({ index }) => !selectedMap[index]);

if (this.options.onRowsDelete) {
if (this.options.onRowsDelete(selectedRows) === false) return;
const deleteResult = await this.options.onRowsDelete(selectedRows);
if (deleteResult === false) return;
}

this.setTableData(