gridstack.js icon indicating copy to clipboard operation
gridstack.js copied to clipboard

getCellFromPixel fails when data-gs-current-height is zero

Open lopezcjf opened this issue 9 years ago • 4 comments

I have migrated from version 0.23 to 0.30 and the getCellFromPixel function is failing for me.

On my scenario the grid stack container is initialized like this:

this.$el.gridstack({ cellHeight: 20, width: 24, verticalMargin: 10 });

The initial state of the gridstack container has height = 0.

I use gridstack to let the users create custom forms on which they can drag and drop controls into the gridstack. When they drop a form control, a function is executed to generate the item in the gridstack. This function calls getCellFromPixel to calculate the position.

The following line of the getCellFromPixel function is failing for me because the initial state of data-gs-current-height is zero

var rowHeight = Math.floor(this.container.height() / parseInt(this.container.attr('data-gs-current-height')));

The line in version 0.23 was:

var row_height = this.opts.cell_height + this.opts.vertical_margin;

... and this was working fine becase the values were taken from my gridstack options.

lopezcjf avatar Apr 07 '17 03:04 lopezcjf

@lopezcjf Could you put together a jsfiddle? Also, what was your previous value in 0.23?

radiolips avatar Apr 19 '17 13:04 radiolips

I just want to note that if the height is 0, this probably should not work. If the height is 1, wouldn't this work fine?

radiolips avatar Apr 19 '17 13:04 radiolips

Closing due to inactivity. Please reopen if there's still an issue.

radiolips avatar May 28 '17 16:05 radiolips

Hello @radiolips : can you please reopen this. I am using Ngx-gridstack where users can drag and drop the widgets from one div to another. After dropping the widget, we can use the mouse co-ordinates to calculate the cell positions. But the problem is data-gs-current-height is set to 1 and because of this, no matter where i drop the widgets, it ends up showing in the first row. Can you please let me know how to update 'data-gs-current-height'

pagadalasrikanth avatar Feb 05 '19 13:02 pagadalasrikanth