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

Dragging widget into parent grid and nested child grid #992

Closed
ygalanter opened this issue Apr 23, 2019 · 15 comments · Fixed by #1908
Closed

Dragging widget into parent grid and nested child grid #992

ygalanter opened this issue Apr 23, 2019 · 15 comments · Fixed by #1908

Comments

@ygalanter
Copy link

I am trying to create this behavior and not sure whether Gridstack supports it or not. I have 3 grids: Grid1, Grid2, and Grid3. Grid1 is a standalone grid and Grid3 is nested inside Grid2. I need to be able to drag widgets from Grid1 both into Grid2 (outer grid) and into Grid3 (nested grid). Following samples I was able to drag widgets between 2 top level grids and create a nested grid, but not combining these 2 together. If this is supported - any pointers are appreciated.

@DamonMuscle
Copy link

@ygalanter I just meet the same problem? Have you resolve this problem? If so, how? Looking forword for your reply. Thank you very much.

@Altraya
Copy link

Altraya commented Jul 23, 2019

I think you can take a look at this #133. I think you need to play with the property "AcceptWidget" and css selector to achieve this.

@adumesny
Copy link
Member

adumesny commented Dec 22, 2019

#1105 I just checked in will get you almost there - I updated nested.html to show drag&drop between 2 nested grids, but dragging a regular item into another nested one has tons of issues - it wants to push the outer one first, then can drop into it - causing issues of 2 drop targets. You can un-comment some settings to try.

Not an easy fix

@adumesny adumesny changed the title Dragging widget from one grid into another, nested one Dragging widget into parent grid or nested child grid Dec 5, 2020
@adumesny adumesny changed the title Dragging widget into parent grid or nested child grid Dragging widget into parent grid and nested child grid Dec 5, 2020
@adumesny
Copy link
Member

adumesny commented May 26, 2021

@RdeWilde in https://gridstackjs.com/demo/nested.html

  1. do you expect "regular item" (green) to move "nested 1" out of the way and also being able to be dropped it inside (becoming a pink item) ? if so we can't have both without an explicit Alt key press or something... which is somewhat hidden, but I don't think we can differentiate using just gesture.

  2. dragging pink item "0" to parent yellow grid doesn't need special key (gesture explicit of dragging out, then will be be parented by yellow and push items, unless Alt key... BUT that doesn't work work moving pink between subgrids as it would leave and go to parent first). this is why this is tricky...

  3. can "regular item" be turned into a nested grid (drag another item into it, with Alt key) and would you need to say ahead of time what items can become nested grid and which ones cannot ? see 4

  4. in the demo nested 1 & 2 have 6 columns layout (parent 12) - if we automatically convert any item into a grid, what column count would we use (set it per item config ?)

  5. if I drag item0 over item1 with Alt key to drop into, do I convert item1 into subgrid of how many columns ? since item0 is same size (or could be bigger) it would take entire item1 columns - not clear what's expected here.

as you can see this is not easy to even design...

@RdeWilde
Copy link

RdeWilde commented May 28, 2021

Thanks @adumesny for setting an outline. I have limited experience ofcourse, you are the expert here, but here's my thought:

  • Using a key is fine with me.
  • Or you have to divide items into different drop targets. 33% left is insert left, 33% right is insert right, other 34% is nest inside.
  • Or you can have an icon inside the div to start dragging for nesting. Stripo has such labels in their editor
  • Or show a context menu/popup on drop about what action to take
  1. I don't get it, but i do understand it is not easy. Maybe check how other ui's handle this?

  2. For my use case, I have a special type, so I can mark them as subgrids ahead of time. But if you can make it more generic, that would probably help other people a lot. But it's fine with me for now to keep scope small and only be able to drag into these special types.

  3. Same number of columns as before, with max of grid column size. I think you can't really convert it, converting 6/12 to */5 would require rounding. I would just keep it as is.

  4. As said in 3) I'm fine with this being out of scope for now.
    If you WOULD implement it, it depends on how/where the subgrid is being created, and maybe parameterize that. But I can understand if you can't pull that off right now.

@adumesny
Copy link
Member

adumesny commented May 28, 2021

@RdeWilde comments:

| Or you have to divide items into different drop targets. 33% left is insert left, 33% right is insert right, other 34% is nest inside.

wouldn't work as you drag over the first 1/3rd, the item would be pushed out of the way and you couldn't get to the mid point to insert nested instead (would be weird to bring item underneath again if you continue moving over nothing to insert)

| Or you can have an icon inside the div to start dragging for nesting. Stripo has such labels in their editor

as a lib I can't insert any affordances (I don't even enforce the type of DOM element just added classes) BUT you sure could and switch mode (insert vs move) for them. I think I will add that as a mode and have Alt key by default switch mode, but you could add UI to control which mode you're in.

| Or show a context menu/popup on drop about what action to take

again, lib can't have UI and you can't do after the fact as the feedback would be move or insert but not both...

  1. & 4. I think I will require items that can be subgrid to be set ahead of time because I need to know the column count/cellHeight, which may need to be different from the parent.

@RdeWilde
Copy link

Sounds good to me @adumesny

@arclogos132
Copy link

arclogos132 commented Dec 22, 2021

  1. do you expect "regular item" (green) to move "nested 1" out of the way and also being able to be dropped it inside (becoming a pink item) ? if so we can't have both without an explicit Alt key press or something... which is somewhat hidden, but I don't think we can differentiate using just gesture.

No Alt key, no moving "nested 1" out of the way. I just need dropping in (which works now)

  1. dragging pink item "0" to parent yellow grid doesn't need special key (gesture explicit of dragging out, then will be be parented by yellow and push items, unless Alt key... BUT that doesn't work work moving pink between subgrids as it would leave and go to parent first). this is why this is tricky...

I need to drag an item out of a subgrid into a parent grid, and vice-versa.

  1. can "regular item" be turned into a nested grid (drag another item into it, with Alt key) and would you need to say ahead of time what items can become nested grid and which ones cannot ? see 4

It would be an awesome feature, but I personally don't need this right now, considering how difficult it would be to implement.

  1. in the demo nested 1 & 2 have 6 columns layout (parent 12) - if we automatically convert any item into a grid, what column count would we use (set it per item config ?)

No need to convert an item into a nested grid for now.

  1. if I drag item0 over item1 with Alt key to drop into, do I convert item1 into subgrid of how many columns ? since item0 is same size (or could be bigger) it would take entire item1 columns - not clear what's expected here.

Same as my answer to Q4.

@adumesny

@arclogos132
Copy link

arclogos132 commented Dec 22, 2021

https://github.com/gridstack/gridstack.js/blob/master/demo/nested.html#L50

acceptWidgets: '.grid-stack-item.sub', // only pink sub items can be inserted, otherwise grid-items causes all sort of issues

This is where I am stuck. I need to set acceptWidgets: '.grid-stack-item' (or true) to the subGrid and its parent grid.
If I have this on both grids, I can drag an item out of the sub grid into its parent grid, but cannot put it back in, because the sub grid will move around dodging my dragging item.

@arclogos132
Copy link

r.mov

Video of not being able to put an item back into a sub grid, while dragging it out of the sub grid into its parent grid works fine.

adumesny added a commit to adumesny/gridstack.js that referenced this issue Dec 23, 2021
* fix to make gridstack#992 better going forward as I'm focusing on nested grids again
* dragging sub item between grids no longer get clipped by parent
* removed basePosition.aboslute option as I'm not sure how we can make it work
(parent has position.relative which will clip us otherwise)
* nested.html you can drag pink items between grids (h5 case, JQ still clipps)
@adumesny
Copy link
Member

adumesny commented Dec 27, 2021

got most of it working for upcoming release... thanks to @arclogos132 for actually funding this!

20211226_212858.mp4

@arclogos132
Copy link

That looks beautiful

adumesny added a commit to adumesny/gridstack.js that referenced this issue Dec 29, 2021
* fix gridstack#992
* we now support dragging into and out of nested grids from parents
* nested.html was updated to showcase this, settings all grids to accept the same widgets. using CSS to differentiate nested items vs not for styling/demo purpose only.
* tested nested, float nad two.html - all seem to continue working (this was a lot of work to fine tune)

* also fix gridstack#1558 as we no longer cache the grid position (as we may move when items are placed elsewhere) but get it on every move to reflect latest data

Thank you [@arclogos132](https://github.com/arclogos132) for sponsoring it.
@adumesny
Copy link
Member

some issue remain (nested within nested break things) - re-opening

20211229_092538.mp4

@adumesny adumesny reopened this Dec 29, 2021
@adumesny
Copy link
Member

adumesny commented Dec 30, 2021

fixed

20211229_221207.mp4

adumesny added a commit to adumesny/gridstack.js that referenced this issue Dec 30, 2021
* remaining fix for gridstack#992 to prevent a nested grid from going inside another until we can do the right thing down the line. Very broken otherwise
* also fixed heuristics to work like regular items (ignore enter/leave for sub grid dragging)
adumesny added a commit to adumesny/gridstack.js that referenced this issue Sep 25, 2022
* more partial fix for gridstack#1009 and gridstack#992
* you can now drag a nested grid over another one and nest it deeper (992)
* fixed size transition
* fixed handlers not set when nesting

TODO: fix pause to work for enter/leave, more nested testing. Fix tests
@adumesny
Copy link
Member

got the nested drag (which was disabled) fixed as part of #1009 (changelist #2052) for v7

20220926_070947.mp4

but the mouseenter event is used today to add items to a grid, when it should really be 50% coverage like between items - so you can't really push vs nest between sub-grid (depending on where your cursor is) - that will have to be future tweaks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants