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

Cannot move widget horizontally (Allow horizontal swapping without creating new rows) #149

Closed
amrbahaa opened this issue May 24, 2015 · 50 comments · Fixed by #1621
Closed

Comments

@amrbahaa
Copy link

for example : i have a grid with fixed 4 columns and four rows When i was trying to move the widget Horizontally and no place for the other widgets to slide up or down , the end result is you will not be able to move that widget unless there is enough space for other widgets to slide up/down.

is there any way to make the other widgets to slide left/right? so i can move any widget when i have a fixed width and height grid with full capacity widgets.

@amrbahaa amrbahaa changed the title Cannot move widget horizontally Cannot move widget horizontally (Allow horizontal swapping without creating new rows) May 24, 2015
@abologna-r7
Copy link

👍
I think the reordering/collision strategy should be change (or have multiple strategies) to work as a swap rather than a push.

@jffaust
Copy link
Contributor

jffaust commented Jun 5, 2015

👍
I have a grid with fixed width and height and when the grid is full, I can't move widgets horizontally. It is possible though to move them vertically. I would like a solution as well.

@ceuk
Copy link

ceuk commented Jun 26, 2015

👍

It's a bit unintuitive as well that when there are two widgets in a row you can't drop one in between them without them both moving down

@ghost
Copy link

ghost commented Jul 8, 2015

👍
I have done a little research and gridster appears to have a working solution for this.
ducksboard/gridster.js#54. Not sure if it works or not.
Still need a solution for gridstack!

@ghost
Copy link

ghost commented Jul 9, 2015

In https://github.com/dustmoo/gridster.js the horizontal swap works with identical sized items. It's a little difficult to swap horizontally when the items are different sized, that way the grid must expand(because one item might be too big for the swappers spot) but cannot because it is at a fixed number of rows.

@asonarya
Copy link

👍 Has anyone found a solution to this?

@joelcuevas
Copy link

+1. It's too hard to simply move to the right a widget without messing up everything else... I have found that the current behavior is counter intuitive for the most of my users.

If somebody --with more understanding of the gridstack internal code than me-- is willing to propose a solution, I'll be more than happy to help to develop it. :)

@h-nazzal
Copy link

h-nazzal commented Aug 5, 2015

it's already in the works ... i am currently refactoring the old collision detection code.
i have some pretty good results handling ~ 300 widgets with no lag or stutter what so ever.
i will implement this feature also. i know that exact code that is responsible for the behavior and it's just a simple fix.

@ghost
Copy link

ghost commented Aug 6, 2015

@h-nazzal Thank you! I look forward to it.

@yedidmh
Copy link

yedidmh commented Aug 6, 2015

Cool!

On Wed, Aug 5, 2015 at 9:23 PM, alan12111 [email protected] wrote:

@h-nazzal https://github.com/h-nazzal Thank you! I look forward to it.


Reply to this email directly or view it on GitHub
#149 (comment)
.

@asonarya
Copy link

asonarya commented Aug 6, 2015

Nice!! Just curious when do you plan to merge it? @h-nazzal

@h-nazzal
Copy link

h-nazzal commented Aug 6, 2015

soon enough maybe today or tomorrow! :)

@asonarya
Copy link

asonarya commented Aug 6, 2015

Wonderful!

@ghost
Copy link

ghost commented Aug 7, 2015

I am excited 👍

@asonarya
Copy link

asonarya commented Aug 7, 2015

Hi @h-nazzal have you been able to merge it yet? just wondering

@h-nazzal
Copy link

h-nazzal commented Aug 8, 2015

sorry you guys .. i just had a problem with certain widget sizes not being moved correctly i have to fix that before i post the changes ..

@ghost
Copy link

ghost commented Aug 8, 2015

@h-nazzal Would it work if they were all the same size?

@h-nazzal
Copy link

h-nazzal commented Aug 8, 2015

yes it would ..
for example if you have a raw of 1 unit widgets (making a total of 12 widgets) and you moved widget # 5 to widget # 6 position then widget # 6 will move to widget # 5 position and doesnt go into a new raw.

but the current problem is that with different sizes you have to predict the width and the distance that each widget has to move (which is sort of solved by moving the widgets one block at a time)
im working on making the current implementation feel as natural as possible, but i cant provide a solution with bugs (if you know what i mean :p )!

@asonarya
Copy link

asonarya commented Aug 8, 2015

@h-nazzal could you please show what you have for the same size widgets? I would like to help. Thanks

@h-nazzal
Copy link

h-nazzal commented Aug 8, 2015

the code below is proven to be non-working. so with that in mind here it is.
it is only safe if you have equal size widgets which i dont think is the case for every one using this plugin.

for now i will not work with this code any more .. im going to go for a full rewrite of the collision detection mechanism as working with it is seriously hard.

    GridStackEngine.prototype._fix_collisions = function(node) {
        var self = this ,
        block_dir = {left : false , right:false} ,
        x;

        this._sort_nodes(-1);
        var nn = node, has_locked = Boolean(_.find(this.nodes, function(n) { return n.locked }));
        if (!this.float && !has_locked) {
            nn = {x: node.x, y: node.y, width: node.width, height: node.height};
        }

        var collision_nodes = _.filter(this.nodes, function(n) {
            return n != node && Utils.is_intercepted(n, nn);
        }, this);

        if (_.isEmpty(collision_nodes) ) {
            return;
        }else{
            _.each(collision_nodes,function(collision_node){
                //detect horizontal collision if there are any collisions found
                _.each(self.nodes, function(n) {
                    if(n.y === collision_node.y){
                        var collision_X = collision_node.x-1 < 0 ? 0 : collision_node.x - 1 ;
                        if(n.x === collision_X ){
                            block_dir.left = true;
                            return true;
                        }else if(n.x === collision_node.x + 1){
                            block_dir.right = true;
                            return true;
                        }                            
                    }

                }, this);

                if(!block_dir.left){
                    x = collision_node.x - 1 < 0 ? 0 : collision_node.x-1 ;
                }else if(!block_dir.right){
                    x = collision_node.x+1;
                }else{
                    x = collision_node.x;
                }

                self.move_node(collision_node, x , node.y + node.height,
                collision_node.width, collision_node.height, true);  
            });
        }
    };

DO NOT USE IN PRODUCTION , USE IT AT YOUR OWN RISK :)

@steezeburger
Copy link

I guess this is still in the works? Setting height: 1 does not allow me to swap or move items.

@radiolips
Copy link
Member

That's correct. I believe it will be readied for v1.0.0. It may be in 0.3.0, but is very unlikely to make it into the current dev build. As you can see, the issue remains open and will stay open until it's been resolved.

@radiolips radiolips added this to the v1.0 milestone Feb 22, 2016
@steezeburger
Copy link

Awesome, I'll play around with the patch above as it fits my use case and then wait for an official fix later on. Thanks for the quick reply.

@tchyong
Copy link

tchyong commented Mar 18, 2016

May i know when v1.0 will be release for this enhancement feature?

@mandys
Copy link

mandys commented Apr 1, 2016

@h-nazzal with what version does your code work ? I know it doesn't work with the latest one but I tried with v0.23 which was released last year and even with that it's not working. I am trying with equal size widgets. Any help would be appreciated.

@sailajachellu
Copy link

I am having the same issue. Can anyone let me know whether this is resolved. if yes, please let me know the version to take.

@h-nazzal
Copy link

@Shiva4393 @sailajachellu im not working on this anymore.
as i have said before i moved to my own custom solution.

@jamdav16
Copy link

Keen to see this feature too if someone else can develop a solution.

@Shiva4393
Copy link

@h-nazzal Can you please share your custom solution with an example which fixes this issue?

@Altraya
Copy link

Altraya commented Jul 15, 2019

+1 Do you have any news for this issue ?

@adumesny
Copy link
Member

@h-nazzal

i know that exact code that is responsible for the behavior and it's just a simple fix.
.... the code below is proven to be non-working....I'm going to go for a full rewrite of the collision detection mechanism as working with it is seriously hard.

aaah... aaah :)
guessing we never had a working (non trivial same size) working version ?
I might take a look at the current heuristic as it doesn't appear to move objects when past half point (like #1094), and could check for swap if size happen to be the same. No promise

@kevinlandsberg
Copy link

Hi guys, is it still work in progress? Would be nice to have this maybe as a gridstackoption...
Having only 3 items in a 1 row and 3 column width, all items same width and height, want to have the possibility to move item 1 to position of item 3 and have them just swap positions, possible?

@adumesny
Copy link
Member

adumesny commented Dec 9, 2020

I started looking at it last weekend and may have to re-write entire collision heuristics at some point... $$ donation would certainly help as this is a BIG task.

Update: I should have some time during the holidays to look at this now that 3.x Html5 is out and solid.

@adumesny
Copy link
Member

adumesny commented Dec 14, 2020

Update: I spent the weekend on this and have swapping on same sized items working in a private branch, which is now the default for top gravity float: false rather than push down (feels more natural IMO), and also used on floating grids if the grid is full and cannot create new rows (maxRow set). Also fixes going down and not swapping right away until you are past the same sized object, and bunch of other oddities and Inefficiencies...

Still need to prevent larger items from swapping unless they are 50% covered, doing collide on the most covered item (not first one) and lot more testing... Hopefully this 5y old most wanted feature will make it now...

Horizontal swapping of different sized objects will need to wait for gravity: left feature (#754) which is a totally different ball game.

@kevinlandsberg
Copy link

kevinlandsberg commented Jan 29, 2021

Behaviour like this is expected:

http://sortablejs.github.io/Sortable/#grid

@adumesny
Copy link
Member

adumesny commented Jan 29, 2021

@kevinlandsberg if you drag 1 over 9 in ^^ it reflows the list, which may or may not be what you want. I have it swap 1 <-> 9 instantly (in my swapping branch). Or course the example they give is VERY simple (all same size and full flowing grid). Gridstack can handle any size combination and empty space with items floating, which is a much harder problem...

Anyway with my swapping code it behaves much better IMO, but the edge cases are hard to fix. I need to find time to finish it up.

And donation are welcomed as always since I'm not getting any help on these...

@kevinlandsberg
Copy link

I will Donate some Money if this Feature Works...😂

@adumesny
Copy link
Member

adumesny commented Feb 1, 2021

yeah right... I already spent >20 hours on this and while I have it mostly working, there is still a lot of testing to make sure I didn't break something else. Already got burned fixing 3 issues for someone else and not getting even a thank you after 3 weeks. I've only gotten 1 donation for #1094 which is related and yet multiple people say they would donate...

guess what ? it take a LOT of work to create this lib and I spent countless weekends and holidays on this. Because of that I'm actually thinking of turning my work into a licensed version. then people will actually have to pay to use it.

@dahacouk
Copy link

dahacouk commented Feb 1, 2021

@adumesny would you consider setting this up on https://opencollective.com ? It's much more transparent, and it would also get you exposure. I need to ask my team if they think your project works for us. And if the answer to both those questions is yes then I will definitely donate to the project. Cheers!

@adumesny
Copy link
Member

adumesny commented Feb 1, 2021

@dahacouk would have to read more, but I'm not trying to open a charity per say... thanks.

adumesny added a commit to adumesny/gridstack.js that referenced this issue Feb 15, 2021
big overall of the collision dectection code - you can now:
* swap items of same size vertically/horizontally when grid is full (maxRow)
***** this has been 5.5years in the making and the most asked question ****
It is now also the default in float:false as it feels more natural than pushing new row
(could add Alt-key to get either behavior of push vs swap ?)
* moving items down or up behave the same way (used to have to push WAY past to insert after)
* optimized the collision code to not do extra work multiple times and only check
if change and not tried before
* heuristics now checks for >50% past the grid mid point (taking margin into account)a

TODO part II:  handle mid point of dragged over items rather 50% of row/column
and check for the most covered when multiple items collide.

* fix gridstack#149 gridstack#1605 and partial gridstack#1094 (need better support for larger items mid point)
@adumesny
Copy link
Member

adumesny commented Feb 15, 2021

and donations are pouring in!!!! (I wish) 5.5y years in the making, in the next release v3.4 or v4.0

default float:false (top gravity)

20210215_102443.mp4

float:true case

20210215_103145.mp4

maxRow:3 for full grid, even if float=true

20210215_103416.mp4

@dahacouk
Copy link

@dahacouk would have to read more, but I'm not trying to open a charity per say... thanks.

I hear you. You don't have to set up a charity, by the way. In the main, it's about being transparent and open. It's working very well for a lot of open source projects (big and small).

Great demos by the way.

@kevinlandsberg
Copy link

kevinlandsberg commented Feb 15, 2021

Woooooow thank you! Release it and i will donate! Cheers!!!

@adumesny
Copy link
Member

@dahacouk I take it your team isn't using it then... v4 has been released. not sure why I need to be transparent about the peanut support I've been getting so far...

@adumesny adumesny unpinned this issue Sep 23, 2022
@adumesny
Copy link
Member

adumesny commented Oct 1, 2023

@dahacouk and others, I've added github sponsor so you can see donations and hopefully make it easier to do...

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.