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

Deleting rows with Action Button #340

Open
hamodey opened this issue Feb 9, 2023 · 1 comment
Open

Deleting rows with Action Button #340

hamodey opened this issue Feb 9, 2023 · 1 comment

Comments

@hamodey
Copy link

hamodey commented Feb 9, 2023

Hi,

I have a datasheet that works great and fine, however I would like to add an "Action" column at the end of the datasheet to be able to delete the current row.

So all rows will have a delete button and I can delete that row and the size of the sheet will get smaller.

Thanks

@navidadelpour
Copy link

Hi @hamodey,

  1. Define your delete function which updates your state of rows:
function deleteRow(indexToRemove) {
  setState((prevState) =>
    prevState.filter((row, index) => index !== indexToRemove)
  );
}
  1. Add an actions column when you are creating your grid:
const grid = state.map((rowData, index) => {
  return [
    { value: rowData.firstName },
    { value: rowData.lastName },
    {
      forceComponent: true,
      component: <button onClick={removeRow.bind(this, index)}>Delete Row</button>,
    },
  ];
});

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

No branches or pull requests

2 participants