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

onRowsDelete not functioning properly as an async function #1277

Open
T-kON99 opened this issue May 6, 2020 · 3 comments
Open

onRowsDelete not functioning properly as an async function #1277

T-kON99 opened this issue May 6, 2020 · 3 comments

Comments

@T-kON99
Copy link

T-kON99 commented May 6, 2020

When handling onRowsDelete and returning false in an async function, the selected row still gets deleted even though it shouldn't

Expected Behavior

Returning false in an async function should prevent deletion of the selected row as the documentation stated

Current Behavior

Returning false in an async function still deletes the selected row anyway triggering the re-render state of the table.

Steps to Reproduce (for bugs)

handleDelete = async (rowsDeleted) => {
    return false;
};
render() {
    return(
        <MUIDataTable 
            data={data}
            columns={columns}
            options={{
                onRowsDelete: this.handleDelete,
                responsive: 'scrollMaxHeight',
                searchPlaceholder: 'Search...'
            }}
        />
    );
};

Will result in MUIDataTable deleting the selected row even though the return value is false.

When the handleDelete is not an async function, it works as expected.

Online example is here

Your Environment

Tech Version
Material-UI-Core ^4.9.9
Material-UI-Icon ^4.9.1
MUI-datatables ^2.14.0
React ^16.12.0
Browser Chrome Version 81.0.4044.129 (Official Build) (64-bit)
@patorjk
Copy link
Collaborator

patorjk commented Jun 9, 2020

There's an open PR for this feature to be async: #835

The main thing holding it up is getting async/await to transpile correctly for the library.

As a workaround, a custom delete operation can be written using the customToolbarSelect option.

@T-kON99
Copy link
Author

T-kON99 commented Jun 17, 2020

For now I switched from using async onRowsDelete to the sync version of it. I think #835 main issue is using MaterialUI for the design which is not transpiling correctly for the webpack is that right?

@patorjk
Copy link
Collaborator

patorjk commented Jun 17, 2020

Correct, the transpiling has issues with async/await. If that were resolved, onRowsDelete could be made async.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants