angular2gridster icon indicating copy to clipboard operation
angular2gridster copied to clipboard

How to get griditem index position after re-positioning & how to programatically/manually change griditem position/order

Open amit509 opened this issue 6 years ago • 7 comments

Hi,

How to get griditem index position after re-positioning & how to programatically/manually change

Can anyone help me out ??

amit509 avatar Sep 11 '19 05:09 amit509

Hi, it depends on how you understand the index position of the items? From left to right and then next row etc.? Do your all items have the same size? In general you can calculate the index out of the gridster item coordinates.

swiety85 avatar Sep 11 '19 09:09 swiety85

Do your all items have the same size? - No. Can you help me out to calculate the index out of the gridster item coordinates? If possible please provide an example or snippet.

Thanks in advance.

amit509 avatar Sep 11 '19 12:09 amit509

Hey Swiety85 can you please help me out on this?

amit509 avatar Sep 13 '19 05:09 amit509

Calculate the index out of the gridster item coordinates:

items
  .sort((prev, next) => prev.x !== next.x ? prev.x - next.x : prev.y - next.y)
  .map((item, index) => ({item, index}))

swiety85 avatar Sep 13 '19 19:09 swiety85

Hey thanks for your quick reply. I have tried your solution, index is appended as 0, 1, 2, 3, 4. But after dragging object 2 to position 0 doesn't update the index position. When we drag and drop widget to another position its index position should be changed but it is not changing. I think i am missing something. Please look into the below example. stackblitz

amit509 avatar Sep 16 '19 04:09 amit509

You use responsiveOptions with different item coords in different breakpoints. First of all you should get rid of responsiveOptions from your config to have always the same gridster positions (x, y) in every resolution. Then it should work. :)

swiety85 avatar Sep 17 '19 08:09 swiety85

I have a similar issue as well @swiety85. The only way I can remove my responsive options is when the gridster items can wrap down when it does not space for the item. Is there any way we can do that?

SunilManthenaG01 avatar Sep 30 '19 17:09 SunilManthenaG01