-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
Hi, I've been struggling a lot trying to get multiple controlled grids working with React. At Grafana we are exploring alternatives to react-grid-layour and gridstack seems interesting.
I've created this demo that sort of solves the issue dprokop#1, but it feels like it's hacky.
A couple of questions from my side:
- Is there a way to tell gridstack not to create "phantom" element, when grid item is dropped from one grid to another? I've solved it by identifying the grid items by
<gridId>:<itemId>and removing the phantom one manually by using theremoveWidgetmethod. - The
removeAllin the batch update in react demo that you provide triggers theremovedevent on the grid. It makes it impossible to change the state of the grid from which the item is removed. Basically what I want to do is to remove item from the state when it's moved from one grid to another, and then re-initialize gridstack. To achieve that in my demo I'm relying on a silentremoveWidgetcall again: https://github.com/dprokop/gridstack.js/pull/1/files#diff-857613860ab6ab3d2b25db0b15493cce1fb0fcf3a188fdf199ed129b1d6e6965R86 . The demo when performed on code sandbox throws a React error related to the underlying dom being modified by gridstack (basically widget dom element is removed and React goes funky with it). Interestingly enough the demo does not suffer from this when run locally (try https://github.com/dprokop/gridstack.js/tree/dprokop/multi-grid-react) - When moving items from one grid to another at some point the grid container starts growing in a weird way - can you provide some insights on why this may be happening? I went through the code but couldn't figure this out yet. The phenomenon is visible on the attached video of my demo. Looking into the generated html it seems like
gs-current-rowis being increased with every interaction.
Screen.Recording.2022-11-03.at.14.37.38.mov
- Do you have any suggestions on how to reliably destroy gridstack instances when react component is unmounted? I've tried to do it the legitimate react way (via useEffect return callback) but unfortunately, this is basically breaking gridstack all together with the follwing error:
gridstack.ts:1240 Uncaught TypeError: Cannot set properties of undefined (setting 'removedNodes')
at a._triggerRemoveEvent (gridstack.ts:1240:19)
at dd-gridstack.ts:339:15
at Object.drop (dd-gridstack.ts:134:9)
at l.triggerEvent (dd-base-impl.ts:40:34)
at l.drop (dd-droppable.ts:146:10)
at l._mouseUp (dd-draggable.ts:245:31)
_triggerRemoveEvent @ gridstack.ts:1240
(anonymous) @ dd-gridstack.ts:339
(anonymous) @ dd-gridstack.ts:134
triggerEvent @ dd-base-impl.ts:40
drop @ dd-droppable.ts:146
_mouseUp @ dd-draggable.ts:245
dd-gridstack.ts:598 Uncaught TypeError: Cannot read properties of undefined (reading 'removeNode')
at o.GridStack._leave (dd-gridstack.ts:598:15)
at dd-gridstack.ts:257:19
at Object.dropover (dd-gridstack.ts:134:9)
at l.triggerEvent (dd-base-impl.ts:40:34)
at l._mouseEnter (dd-droppable.ts:104:10)
Steps to reproduce
Partially working demo: https://codesandbox.io/s/blazing-browser-6dqptj?file=/src/App.js
You can also run https://github.com/dprokop/gridstack.js/tree/dprokop/multi-grid-react which even though is the same as above, it works better ;)
I would appreciate any help from your side!
Meierschlumpf and fredericrous