material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Add onRowCancel function on editable tables

Open jakeleventhal opened this issue 7 years ago • 8 comments

Is your feature request related to a problem? Please describe. I have a custom edit component that is a select dropdown with two options (A, and B)

My current idea is to have a state variable that is currentRowOption set to '' initially. In my editComponent, before returning the select component, I set the state variable to the value of the row, if and only if the state variable is equal to ''. I am able to to set the state variable back to '' in the onRowUpdate function, but I need to be able to reset it if the editing is cancelled.

Describe the solution you'd like A function for onRowCancel

jakeleventhal avatar Jun 05 '19 00:06 jakeleventhal

I found a way to do this using material tables props that gets passed into the onedit function.

I still think this would be useful

jakeleventhal avatar Jun 05 '19 20:06 jakeleventhal

@jakeleventhal Can you post an example of how you got it to work please?

czevolk avatar Jun 07 '19 20:06 czevolk

What i did was not use a state variable and instead use the supplied props on change function like this

<TextField
    onChange={(e) => props.onChange(e.target.value)}
    value={props.value}
 />

This works, but for something more detailed, the onRowCancel would be really helpful.

jakeleventhal avatar Jun 07 '19 22:06 jakeleventhal

This is actually not needed. you can override editable.EditRow property that returns MTableEditRow and override onEditingApproved and onEditingCanceled. this applies to both add, update and delete.

chitgoks avatar Apr 12 '20 01:04 chitgoks

onEditingCanceled

seems like onEditingCanceled is not recognized.Do you have an example?

dashName avatar Apr 18 '20 08:04 dashName

components={{
        EditRow: (props) => {
          return (
            <MTableEditRow
              {...props}
              onEditingApproved={(mode, newData, oldData) => {
              }}
              onEditingCanceled={(mode, rowData) => {
              }}
            />
          );
        }}
      }

chitgoks avatar Apr 18 '20 08:04 chitgoks

components={{
        EditRow: (props) => {
          return (
            <MTableEditRow
              {...props}
              onEditingApproved={(mode, newData, oldData) => {
              }}
              onEditingCanceled={(mode, rowData) => {
              }}
            />
          );
        }}
      }

Hey I was able to use this but it wont allow me to select any dropdown value of any cell in my editComponent.I am doing something like this: components={{ EditRow: (props) => { return ( <MTableEditRow {...props} onEditingCanceled={(mode, rowData) => { setParents([]); setName(''); setId(''); props.onEditingCanceled(mode); }} /> ); }} }

dashName avatar May 07 '20 01:05 dashName

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

stale[bot] avatar Aug 05 '20 03:08 stale[bot]