-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Rows are modified with a new property tableData #666
Comments
As it is a big pb at least for me, I am working on it on my branch. If you want, I can make a pull request once it's done. |
Hi @paillave , MT tracks many changes on rows and columns. So i had to change rows and columns. But we may try to add a flag to options make rows and columns immutable. But many features will not work. I am not sure to do this. |
I am working on a solution, I'll make a pull request once it is done. It is an amendment this will require a lot of tests as this property is really used a lot. |
Of course. I can check it after completed. |
I also encountered this issue. Since it seems to take quite a while - i propose a workaround: function getList(){
var returnData = [];
state.data.forEach(element => {
var elCopy = Object.assign({}, element);
delete elCopy["tableData"];
returnData.push(elCopy);
});
return returnData;
} If there is a nicer way feel free to improve it ;-) |
That's what I did, but the grid actually needs this data. Otherwise, the whole context of what the user made against it is forgotten when the reducer (for example) amends a row in the input data set. |
Would it be possible to do a |
I just ran into this too...perhaps the docs should post a warning if you are using Redux. |
It is adding extra property with redux state. How can it be avoided? |
Same here, material table seems to be incompatible with immer. I guess material table should not mutate original state anyways |
This bug is still going on. I have different data views, when switching from table to anything else it has a new unexpected property. Should not be modifying the original data! I am thinking about switching to this (see Material example toward end): |
Another solution you might try. I'm using it without too much issues. Just be careful if you have circular dependencies or some non-serializable stuff data={JSON.parse(JSON.stringify(tabledata))} |
Or even simpler and faster than JSON stringify and parse:
Works like a charm for me. |
Those are no solutions, but workarounds. Using the new hook api is impossible when the data gets mutated. |
@HonzaTuron Nice. It may be slightly hacky, but I can confirm it's working with a reducer. |
@cutamar , you can try something like this to wrap your data:
|
Any progress on this? as much as |
Ha! This issue might have cost me a job interview in a demo project, but the good news is that I have a fix for this in my local branch. I've used ES6 Symbols to decorate the data object with a [tableData] symbol that's only used internally in material-table. To support older browsers I've also included a polyfill. Let me submit a pull, give me a little time to clean up & check it as I was fixing it haphazardly. |
Hi this problem is long know and these fixes where already thought and tested, but the main probkem is, that some users rely on object reference to find matching objects in their data during callbacks. That's why @mbrn rolled back a merged PR to exactly fix this #1174. I think we should either find a way to keep both the old reference data and not mutate or create a breaking change that obj reference is not guaranty anymore. |
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. |
Describe the bug
Might be related to #269 as I have exactly the same pb.
When rendering rows in the grid, the property tableData is added to every row. This is a big problem with redux as its state MUST never be changed. Therefore, issue mentioning a readonly property may come from the fact that immutability frameworks like immer lock objects from the state for them not to be amended afterwards (as redux demands reducers and components to be pure).
To Reproduce
render a list of value in the grid
Expected behavior
at the moment, before the rendering, business objects are directly manipulated by adding a tableData metadata on them:
what may be better instead would be to keep on behaving this way by default, but to permit to get the identifier from the row. If such an option is given, then, instead of getting/setting this "tableData" on the row itself, it can be recovered from a dictionary that is stored in the state.
This way, the input business row is never touched and stored as is in the object that is used by the rendered, and as a sibling property you have all the useful metadata for the rendering purpose.
As ideally, react component should be pure (not modifying its properties), this amendment would help a lot, at moreover it would permit your grid to work with react in any situation.
The text was updated successfully, but these errors were encountered: