Cannot move widget horizontally (Allow horizontal swapping without creating new rows)
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.
:+1: I think the reordering/collision strategy should be change (or have multiple strategies) to work as a swap rather than a push.
:+1: 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.
:+1:
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
:+1: I have done a little research and gridster appears to have a working solution for this. https://github.com/ducksboard/gridster.js/issues/54. Not sure if it works or not. Still need a solution for gridstack!
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.
:+1: Has anyone found a solution to this?
+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. :)
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.
@h-nazzal Thank you! I look forward to it.
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 https://github.com/troolee/gridstack.js/issues/149#issuecomment-128200468 .
Nice!! Just curious when do you plan to merge it? @h-nazzal
soon enough maybe today or tomorrow! :)
Wonderful!
I am excited :+1:
Hi @h-nazzal have you been able to merge it yet? just wondering
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 ..
@h-nazzal Would it work if they were all the same size?
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 )!
@h-nazzal could you please show what you have for the same size widgets? I would like to help. Thanks
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 :)