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

Programatically update a row in DataTable ? #7676

Open
MikeLewell opened this issue Feb 3, 2025 · 4 comments
Open

Programatically update a row in DataTable ? #7676

MikeLewell opened this issue Feb 3, 2025 · 4 comments
Labels
question Issue contains a question about the use of PrimeReact components or the products it supports

Comments

@MikeLewell
Copy link

I am looking for a way to update an entire row or sibling values when using the column editor. Other table libraries have this functionality such as MUI. Does this exist in Prime React ?

@github-actions github-actions bot added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 3, 2025
@melloware melloware added question Issue contains a question about the use of PrimeReact components or the products it supports and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Feb 3, 2025
@melloware
Copy link
Member

I don't think updating a single row is possible. @sja-cslab thoughts?

@sja-cslab
Copy link
Contributor

I'm not exactly sure what "update an entire row" means.
Just sounds like row edit to me.

@MikeLewell
Copy link
Author

Apologies, my description isn't the most clear.

I am asking if there is a way to update an entire row programatically via a call back. ColumnEditorOptions has editorCallback to update the column field. It would be nice if there was a way to also update the entire row value. This is useful when the data is more complex. Such as, when passing a nested structure, where I may need to overwrite an entire object property in the row.

As an aside, I have noticed a couple potential bugs:

  • It appears that nested object properties in the DataTable row are passed by reference to the internal state. This leads to some weird behaviour when edit mode also mutates the source data. I am working around it by deep cloning the DataTable value each time it is passed to the table. Just thought that was worth mentioning.
  • Canceling edit mode retains the internal edited state of object values. It would be nice if edit mode replaced the internal state with the pre-edited row state. I am working around it by forcing a re-render of the entire table.

I think this is a great product, much nicer DX than the alternatives.

@sja-cslab
Copy link
Contributor

sja-cslab commented Feb 5, 2025

I'm still not 100% what you try to achive, sorry.
Row-data is a combined set of column-data that's how it works.
If you want to edit a whole row then, you should just need to edit your sourcedata which should be reflected by the datatable as soon as react re-renders.
You can achive this by e.g. using onRowEditComplete where you get an event including all things you need.
Or by implementing a whole edit yourself (thats what i do).

It appears that nested object properties in the DataTable row are passed by reference to the internal state. This leads to some weird behaviour when edit mode also mutates the source data. I am working around it by deep cloning the DataTable value each time it is passed to the table. Just thought that was worth mentioning.

I've noticed that myself for a while #6738. I cannot remember what exactly happened and why I closed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issue contains a question about the use of PrimeReact components or the products it supports
Projects
None yet
Development

No branches or pull requests

3 participants