-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Update layout when props changed #382
Comments
I'm having a similar problem: when I'm giving my GridItems a new width via Also, I'm not sure, but this is possibly related to this issue: #178 which has apparently been resolved. |
@nikolas If you can get a working webpackbin going (here's one for react-resizable) it would be really helpful for debugging this. |
I had the same issue. Ended up using the layout props (i.e. updating the layout array with new values) of ReactGridLayout component instead of data-grid prop on each widget component. |
@nushydude i did the same but it did not work as i expected, so i just rerender whole component when need, it`s bad solutions, but it works |
Here is a webpackbin, please demonstrate the issue: http://www.webpackbin.com/VymTE3zWG |
I would like to come up with an example but I can't get webpackbin to work at the moment. I've opened an issue with that project here: christianalfoni/webpack-bin#199 |
This should solve this problem: react-grid-layout#382 But may have unwanted side effects if you're relying on the global `layout` array.
If anyone is still wondering, there's a small change you can make in I haven't opened a pull request for this yet because, although it works for my case, I haven't tested this while using the global |
This should solve this problem: react-grid-layout#382 But may have unwanted side effects if you're relying on the global `layout` array.
This should solve this problem: react-grid-layout#382 But may have unwanted side effects if you're relying on the global `layout` array.
This should solve this problem: react-grid-layout#382 But may have unwanted side effects if you're relying on the global `layout` array.
This should solve this problem: react-grid-layout#382 But may have unwanted side effects if you're relying on the global `layout` array.
I'm currently encountering this issue as well. My application state updates the layouts passed to the grid items' data-grid, but no re-render is caused. Even adding layout to this.state and setting layout={this.state.layout} did not fix it (perhaps because my grid items are still using their data-grid). I will try to apply the patch kindly provided by @nikolas above. PS: I am using ResponsiveGridLayout |
Hmm, this patch doesn't seem to work for me. It breaks the grid functionality. @nikolas am I doing something wrong? |
@STRML - I've modified your webpackbin to have a load and save layout buttons; I can't seem to get the layout to update dynamically after loading the saved layout from storage. May you kindly take a look? http://www.webpackbin.com/418oyspOf Thank you EDIT: It doesn't work if you 'save', then drag the layout around a bit, then click 'load'. It does work if you 'save', then click 'generate new layout', then click 'load'. |
This should solve this problem: react-grid-layout#382 But may have unwanted side effects if you're relying on the global `layout` array.
@nikolas there are a few different issues going on; for the way I'm using react-grid-layout, the patch above does not work because the re-render caused by setState isn't even triggered. (setState isnt called) |
@STRML For me, I've made these changes: utils.js:
This does two things:
However, the above will cause issues (I think) for those using the prop ReactGridLayout.prop.layout (I don't use it). So, the fixes above are kludges and only use it if you aren't using the prop 'layout'. |
This should solve this problem: react-grid-layout#382 But may have unwanted side effects if you're relying on the global `layout` array.
I just wanted to leave some notes to help out, here. So, you can get it to work properly, if you follow the exact use-case in "example 7: loading and storing". The error others have made is:
In actuality, you must use BOTH the prop layouts / layout AND data-grid={layout object}, in order to get state storage to work as is:
Doing the above #1 and #2 will ensure you can use the current (as of Feb 2017) code base without doing any custom patching. EDIT: Actually, this still doesn't work fully. You must apply my patch above, and then it will work regardless of if you do #1 or #2 or both #1 and #2. |
@nikolas I found yours introduces another issues. After I applied the patch, the grid layout cannot resize/drag anymore. I can resize or drag item but it goes back to original place when I release it. |
I did @developer94404 said 1 and 2, and it did work for me. |
I was having a similar issue until I realized that I was changing the layout object that was used as a prop for
The problem was that To fix this, I calculate a fresh layout object to pass as a prop to
Now everything works as expected :) |
This should solve this problem: react-grid-layout#382 But may have unwanted side effects if you're relying on the global `layout` array.
This should solve this problem: react-grid-layout#382 But may have unwanted side effects if you're relying on the global `layout` array.
@developer94404 Thank you so much. This was driving me batty and your solution worked perfectly. |
@pkerpedjiev Thanks for the solution on layout change. |
Thanks @developer94404 - it looks like passing in the |
@developer94404's solution worked for me, but just to simplify it for anyone who wanders on this thread (as I imagine this is a pretty integral issue for a lot of projects). Example 1 - Does not work.
Example 2 - Works.
|
@AbsohAbsoh's solution works!!!!!! I've tried to add a button that restore original dimensions of resized elements: dimensions were updated but elements were not compacted. After I've applied AbsohAbsoh's solution all works fine.
Definition of my render:
|
To end the story, please use both "layouts" and "data-grid" props. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 7 days |
The proposed solution isn't working anymore and even if it were working it is a hack for something seemingly simple. Nevertheless, I cannot say with certainty whether it is difficult to implement. However, based on how long the issue was open for, I'd say that it is. Hence, it'd be great if someone could share with us the reason why it is difficult to implement. |
I am also seeing this issue. I am controlling my layout via parent component state (for undo redo of dashboard history) and using the data-grid property on each grid item. The props being passed to the grid item are indeed changing but the layout does not update. Update: |
Wow thank goodness for this thread. Yes I also needed to have both layout and grid-item for changes to trigger a re-render properly. I really think this should be explained in the docs. I'll create a PR for that soon. |
I am using the answer in this stackoverflow question to resize programatically the layout and it works. |
Reading all of this way too late, the important thing is to always generate a new layout item reference, so this would also work: let layout = this.props.layout.map(item => ({...item}));
return (
<ReactGridLayout layout={layout}>{children}</ReactGridLayout>
) |
Also for working for me use: |
How to update layout programmatically? Currently, when i try to set new layout to GridLayout it will be ignored
This is new props that i provided
This is yours component state after i provided new layout
As you can see, props are just ignored, all i need to do is to change children isDraggable on button click
I tried to do the same with inline grid, but it had no effect
The text was updated successfully, but these errors were encountered: