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 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
24 changes: 13 additions & 11 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
@@ -1,12 +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 assign from 'lodash.assign';
import Paper from '@material-ui/core/Paper';
import PropTypes from 'prop-types';
import React from 'react';
import TableBody from './components/TableBody';
Expand All @@ -16,8 +11,14 @@ import TableHead from './components/TableHead';
import TableResize from './components/TableResize';
import TableToolbar from './components/TableToolbar';
import TableToolbarSelect from './components/TableToolbarSelect';
import assign from 'lodash.assign';
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: {},
Expand Down Expand Up @@ -956,14 +957,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(
Expand Down