Closed sosoriov closed 10 years ago
Im facing the same problem...
I still have the problem, any idea?
this probaly makes no sense: https://github.com/ducksboard/gridster.js/issues/335
But the same goes for you, if you want a function to see what I mean let me know ;)
@BarryatVendorpages it would be very useful for me thanks (y)
//Sorts tiles according to position
jQuery.fn.tileposition = function() {
//Gets tile's row
pos = new Array();
$.each(this, function(i,object){
row = $(object).attr('data-row');
pos[i] = {'row' : row, 'current' : i};
});
//Sorts tiles position acording to row
sortedpos = pos.sort(function(a,b) {
return parseInt(a.row,10) - parseInt(b.row,10);
});
//Creates posarray used below to sort object
posarray = new Array();
$.each(sortedpos, function(i,value){
posarray[i] = value.current;
});
// get copy of DOM element array
var copy = this.toArray();
// don't exceed bounds of arrays
var len = Math.min(posarray.length, copy.length);
for (var i = 0; i < len; i++) {
var index = posarray[i];
// make sure incoming index is within bounds of DOM object array
if (index < copy.length) {
// put the index item into the i location
this[i] = copy[index];
}
}
return this;
};
// The above function basically just reorders dom elements/widget into the appropriate order returning another object... at which point I save each value into a database one after another, later each is recalled in appropriate order, gridster is initiated and all is OKAY :D Sorry about the mess of the above function, be sure to optimize it. Its just a rough.
var correctlistofwidgets = $('#listofwigets > li').tileposition();
Good Luck
@BarryatVendorpages Thanks! Your function solves my problem.
@BarryatVendorpages Thanks!!! It works
Here's a rails helper of the same, in case anyone needs it:
def dashboard_ordered(widgets)
pos = []
widgets.each_with_index do |widget,i|
row = widget['row']
pos[i] = { row: row, current: i }
end
sortedpos = pos.sort_by{|widget| widget[:row]}
posarray = []
sortedpos.each_with_index do |widget,i|
posarray[i] = widget[:current]
end
copy = widgets.dup
len = posarray.count
len = copy.count if copy.count < posarray.count
i = 0
while i < len
index = posarray[i]
if index < copy.count
widgets[i] = copy[index]
end
i += 1
end
return widgets
end
I have a problem to load a gridster from serialize object.
Some of my widgets don't appear in the correct position, but in the serialize object they are ok:
My original gridster is:
After serialize and load it appears
This is the serialize object
Any idea of it?
Thanks