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

pass rowIdx to renderEditCell #3511

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dalmolinz
Copy link

@dalmolinz dalmolinz commented May 10, 2024

rowIdx is passed to renderCell but not to renderEditCell. This PR fixes that unless there's any reason otherwise.

In my use case, I'm rendering a custom input component that updates a react-hook-form context, and it references the form field using the dot notation e.g. persons.1.height etc.

The status quo with rdg only exposing row, I have to expand my rows objects to contain their own indexes, or do a rows.findIndex, which forces me to declare columns inside the render cycle and deal with memoization etc. Neither are ideal, especially because the solution is right under our noses.

The proposed PR makes it trivially simple to achieve that:

renderEditCell: ({ rowIdx, column }) => {
  return <input name={`myField.${rowIdx}.${column.key}`} />;
}

`rowIdx` is passed to `renderCell` but not to `renderEditCell`. This PR fixes that unless there's any reason otherwise.

In my use case, I'm rendering a custom `input` component that updates a react-hook-form context, and it references the form field using the dot notation e.g. `persons.1.height` etc.

The status quo with rdg only exposing `row`, I have to expand my rows objects to contain their own indexes, or do a `rows.findIndex`, which forces me to declare `columns` inside the render cycle and deal with memoization etc. Neither are ideal, especially because the solution is right under our noses.

The proposed PR makes it trivially simple to achieve that:

```ts
renderEditCell: ({ rowIdx, column }) => {
        return <input name={`myField.${rowIdx}.${column.key}`} />;
      }
```
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

Successfully merging this pull request may close these issues.

None yet

1 participant