Skip to content

Gravity Parameter #754

Closed
Closed

Description

@ISNIT0

Would be really nice to have a 'gravity' option (top/bottom/left/right) for the direction packNodes moves the tiles.

Currently it's only possible to have no gravity (float:true), or the default which is up/top.

Activity

  1. ZoolWay commented on Aug 31, 2017

    @ZoolWay

    If you take a look at the blog post, https://dylandreams.com/2017/04/26/gridstack-10-coming-soon/ , that's a 1.0 feature. It highly awaited ;)

  2. radiolips commented on Sep 5, 2017

    @radiolips
    Member

    Thanks, @ZoolWay . I have lots of excuses for why version 1 wasn't released yet, but I'll save myself some face and just say: shoot. I missed a deadline badly. I'm working on a plan to increase transparency so that it's more obvious to see the status of all gridstack features. Look for a blog post soon - I'll get into a regular cadence with that as well.

  3. radiolips commented on Sep 5, 2017

    @radiolips
    Member

    (but, yes, it's one of the features in the [uuuugh as-yet-unreleased] version 1.0.

  4. added this to the v1.0.0 milestone on Sep 5, 2017
  5. fictivecreations commented on Sep 13, 2019

    @fictivecreations

    @radiolips Any update on this feature's eta?
    I want to be able to have my grid items get pushed across the row as new widgets are added rather than be pushed down the page.

  6. removed this from the v1.0.0 milestone on Dec 21, 2019
  7. adumesny commented on Dec 21, 2019

    @adumesny
    Member

    @sunlanterns new items are added in the first slot available (autoPosition or missing x,y) first, starting in the top/left corner (that part should be configurable to support rtl). that part wouldn't change.

    but I guess you saying when manually moving a widget around, we push conflicting items down, while you want them pushed to the right (and therefore reflow below ?)

  8. fictivecreations commented on Jan 6, 2020

    @fictivecreations

    @adumesny Sorry for the late response. I think that sounds right.
    In my use case we always add our newest widget at the 0,0 slot. This ends up pushing any pre-existing widget in that spot down, when I would rather it be pushed to the right.

  9. adumesny commented on Jan 6, 2020

    @adumesny
    Member

    @sunlanterns do you have to have new items added at the beginning (0,0) ? because otherwise adding them without explicit x,y would add them in a row as you requested. But I could see supporting a left/right flow as you move things around, instead of pushing down.

    Also @ISNIT0 I don't think 'bottom' gravity makes sense (browser scroll for content) as how far would you put them ? what scenario are you trying to solve ? Tetris game ? :)

  10. fictivecreations commented on Jan 6, 2020

    @fictivecreations

    @adumesny Yes, we have to have them added at the beginning. Just to explain, we have users choosing to add widgets dynamically themselves - and users expect that new widget to show up close to the add widget button, and not possibly out of sight down the page in the next available slot.

  11. adumesny commented on Jan 7, 2020

    @adumesny
    Member

    you might be able to do that yourself for now using similar code to what I recently did in compact() method - make gridstack believe it has no items, add the new one in, then loop over the old ones adding them to their old position (if no conflict, else use autoPosition to find next space).

    would be nice to have contributions on this

  12. fictivecreations commented on Jan 10, 2020

    @fictivecreations

    @adumesny At that point I feel like I'm having to re-implement the positioning logic completely, which is something I don't want to do or I wouldn't have grabbed a grid framework to begin with and written it myself.

  13. pinned this issue on Dec 14, 2020
  14. unpinned this issue on Dec 31, 2020
  15. adumesny commented on Jul 25, 2024

    @adumesny
    Member

    uuuuh, GristackEngine.compact() does it in 8 lines of code (with half handling edges cases you likely don't care) but whatever...

        const copyNodes = this.nodes;
        this.nodes = []; // pretend we have no nodes to conflict layout to start with...
        copyNodes.forEach((n, index, list) => {
          let after: GridStackNode;
          if (!n.locked) {
            n.autoPosition = true;
            if (layout === 'list' && index) after = list[index - 1];
          }
          this.addNode(n, false, after); // 'false' for add event trigger
        });
  16. m7mdyahia commented on Sep 18, 2024

    @m7mdyahia

    Hello @adumesny is there currently a way to restrict the motion items only to right when moving (resolve collisions only to the right and not down) as this

    we already used your library in a large project, but users demand this behavior change

    so Could you give us Idea how could we make it or where to override in the engine, we are willing to contribute

    Otherwise we will have to reimplement everything manually and remove GridStack

  17. adumesny commented on Sep 20, 2024

    @adumesny
    Member

    @m7mdyahia you cannot do the manually collision easily. the above Q was to insert at 0,0 which is different as that is a one time thing...
    there has been request to support a 'list' mode (vs float true:false) which could be added for the right donation.

  18. m7mdyahia commented on Sep 20, 2024

    @m7mdyahia

    You mean by his
    #149 (comment)

  19. adumesny commented on Sep 21, 2024

    @adumesny
    Member

    no that's horizontal swap which already exists... I mean new mode = top | float | list | compact. would be a lot of work...

  20. adumesny commented on Sep 14, 2026

    @adumesny
    Member

    FIY, looking at implementing mode: 'top' | 'float' | 'list' | 'compact' option instead of just the old float:boolean option

  21. added a commit that references this issue on Sep 14, 2026
    61e358b
  22. pinned this issue on Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions