ducksboard / gridster.js

gridster.js is a jQuery plugin that makes building intuitive draggable layouts from elements spanning multiple columns
http://gridster.net/
MIT License
6.04k stars 1.2k forks source link

Issue when Removing Widgets #508

Open ap0091 opened 9 years ago

ap0091 commented 9 years ago

I have this JSFiddle Here: http://jsfiddle.net/558wsrtb/1/

I have created a gridster to read data from my database (but in this JS Fiddle i have hardcoded the JSON).

I am trying to create functionality to remove a widget, but I occur a bug here and there when I try to remove certain widgets when I am not removing in order.

For example: I can remove Store Chart3, CTC Chart2, Web Chart1, and Store Chart0 in this order successfully.

but then I try to remove Store Chart0, CTC Chart2.. it removes Store Chart 2.. and then if i continue clicking to remove CTC Chart2 nothing happens, but when I click Remove Web Chart 1, CTC Chart2 dissapears..

Do i have an issue with my index values or something or is this a bug? The error from console.log: Uncaught TypeError: Cannot set property 'width' of undefined

Thanks!

dtamm commented 9 years ago

Just change this lines

function rem(idrem)
{
    var rem = grid.remove_widget($(".layout_block").eq(idrem), true);
}

to this lines

function rem(idrem)
{
    var rem = grid.remove_widget($("#" + idrem), true);
}

and it will work!

bondt commented 9 years ago

Try this: http://jsfiddle.net/b0ndt/e1Lga24w/2/

Instead of working with ids, work with elements and paths. Note the changed lines:

linkToRemove = '<button onclick="rem(this);">REMOVE</button>';

and

var rem = grid.remove_widget($(idrem).parents(".gs-w"), true);