Coder Social home page Coder Social logo

Comments (7)

michelengelen avatar michelengelen commented on June 11, 2024

Hey @sidneibjunior I did update your code with a working example: Custom edit input

The problem was with your component having the value in state and then updating when you wanted to stop the editing mode. The best way is to let the grid handle the values in the internal state and access it via the props that get passed into the component.

Does this fix your problem?

from mui-x.

sidneibjunior avatar sidneibjunior commented on June 11, 2024

Hey @sidneibjunior I did update your code with a working example: Custom edit input

The problem was with your component having the value in state and then updating when you wanted to stop the editing mode. The best way is to let the grid handle the values in the internal state and access it via the props that get passed into the component.

Does this fix your problem?

Hi @michelengelen, thanks for the response.
I need to store intermediate values in the internal state, otherwise, the user cannot type partial temporary values, like ..
I made it work by moving the setEditCellValue with a debounceMs to the handleChange function, as you suggested in your example.

However, for performance reasons, I'd like to set the value to the datagrid only when the user stops editing the cell. Shouldn't it be possible? Why does having the preProcessEditCellProps prop make any difference in my example?

from mui-x.

michelengelen avatar michelengelen commented on June 11, 2024

I am not sure why, but with adding preProcessEditCellProps we add a Promise to the function. Thats why the execution is not linear.
You can also convert handleKeyDown in your example to an async function:

const handleKeyDown = async (e: React.KeyboardEvent<HTMLInputElement>) => {
  if (e.key === 'Enter' || e.key === 'Tab') {
    const inputEl = e.target as HTMLInputElement;
    const newValue = inputEl.value;
    await apiRef.current.setEditCellValue({
      id,
      field,
      value: newValue,
    })
    apiRef.current?.stopCellEditMode({ id, field });
  }
};

from mui-x.

michelengelen avatar michelengelen commented on June 11, 2024

You cannot fully rely on the Promise, so we cannot chain with a then, but this should do the trick.

from mui-x.

sidneibjunior avatar sidneibjunior commented on June 11, 2024

I am not sure why, but with adding preProcessEditCellProps we add a Promise to the function. Thats why the execution is not linear. You can also convert handleKeyDown in your example to an async function:

const handleKeyDown = async (e: React.KeyboardEvent<HTMLInputElement>) => {
  if (e.key === 'Enter' || e.key === 'Tab') {
    const inputEl = e.target as HTMLInputElement;
    const newValue = inputEl.value;
    await apiRef.current.setEditCellValue({
      id,
      field,
      value: newValue,
    })
    apiRef.current?.stopCellEditMode({ id, field });
  }
};

Interesting. Adding the await really does the trick. Thank you.

from mui-x.

michelengelen avatar michelengelen commented on June 11, 2024

Great ... glad we could help.

from mui-x.

github-actions avatar github-actions commented on June 11, 2024

⚠️ This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@sidneibjunior: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

from mui-x.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.