Open RobFra opened 9 years ago
Please, is it possible to have an answer? Is it a bug or am I doing anything wrong?
I've done something similar but instead of local storage I used a simple cookie. So far is working pretty good for me. You can check the code here. Look for the start and store functions.
I believe that the problem with your code is that you're setting just the data attributes, instead of adding the widgets through gridster.
Instead of this:
$(id_name).attr({ "data-col": value.col, "data-row": value.row, "data-sizex": value.size_x, "data-sizey": value.size_y });
Try this:
gridster.add_widget($(id_name), value.size_x, value.size_y, value.col, value.row);
Hello, thank you very much for your email. I’ll try your suggestion later, I’ll be back to let you know.
Thanks
From: Marcelo Emanoel Bezerra Diniz [mailto:notifications@github.com] Sent: lunedì 17 novembre 2014 15:26 To: ducksboard/gridster.js Cc: Roberta Franchi Subject: [NEWSENDER] - Re: [gridster.js] reload saved settings (#462) - Messaggio da mittente sconosciuto
I believe that the problem with your code is that you're setting just the data attributes, instead of adding the widgets through gridster.
Instead of this:
$(id_name).attr({ "data-col": value.col, "data-row": value.row, "data-sizex": value.size_x, "data-sizey": value.size_y });
Try this:
gridster.add_widget($(id_name), value.size_x, value.size_y, value.col, value.row);
— Reply to this email directly or view it on GitHubhttps://github.com/ducksboard/gridster.js/issues/462#issuecomment-63311331.
Hello Marcelo,
adding widgets I receive the following error:
[cid:image001.png@01D0033B.CFBE8DB0]
And with your code: https://gist.github.com/marceloemanoel/5be3a550f1e7ad45fa3f
I’ve never used RequireJs. Can you say me how to use this function or where do I have to put it? I receive the error: define is undefined.
From: Marcelo Emanoel Bezerra Diniz [mailto:notifications@github.com] Sent: lunedì 17 novembre 2014 15:26 To: ducksboard/gridster.js Cc: Roberta Franchi Subject: [NEWSENDER] - Re: [gridster.js] reload saved settings (#462) - Messaggio da mittente sconosciuto
I believe that the problem with your code is that you're setting just the data attributes, instead of adding the widgets through gridster.
Instead of this:
$(id_name).attr({ "data-col": value.col, "data-row": value.row, "data-sizex": value.size_x, "data-sizey": value.size_y });
Try this:
gridster.add_widget($(id_name), value.size_x, value.size_y, value.col, value.row);
— Reply to this email directly or view it on GitHubhttps://github.com/ducksboard/gridster.js/issues/462#issuecomment-63311331.
Hi Marcelo, here I am again. I think that I’ve found out the problem. It is not working perfectly now but quite better: the problem was that the id of
Thanks
From: Marcelo Emanoel Bezerra Diniz [mailto:notifications@github.com] Sent: lunedì 17 novembre 2014 15:26 To: ducksboard/gridster.js Cc: Roberta Franchi Subject: [NEWSENDER] - Re: [gridster.js] reload saved settings (#462) - Messaggio da mittente sconosciuto
I believe that the problem with your code is that you're setting just the data attributes, instead of adding the widgets through gridster.
Instead of this:
$(id_name).attr({ "data-col": value.col, "data-row": value.row, "data-sizex": value.size_x, "data-sizey": value.size_y });
Try this:
gridster.add_widget($(id_name), value.size_x, value.size_y, value.col, value.row);
— Reply to this email directly or view it on GitHubhttps://github.com/ducksboard/gridster.js/issues/462#issuecomment-63311331.
Hello @marceloemanoel If I want to bind gridster data from database then how to re initialize gridster class if already exists in a page.
I've added the function that I'll paste here below, It seems to work, in fact it saves to localstorage and load from local storage and values are correct but.... when page is reloaded, tiles remain in the original position!. I'm getting crazy, can't understand what I'm doing wrong or maybe is it an issue?
$(function () { //DOM Ready
var gridster = $(".gridster > ul").gridster(
{ widget_margins: [10, 10],
widget_base_dimensions: [200, 225],
serialize_params: function ($w, wgd) { return { id: $($w).attr('id'), col: wgd.col, row: wgd.row, size_x: wgd.size_x, size_y: wgd.size_y, }; },
draggable:
{
stop: function (event, ui) { console.log('inside stop'); var positions = JSON.stringify(this.serialize());
localStorage.setItem('positions', positions);
console.log(positions);
$.post(
"process.php",
{ "positions": positions },
function (data) {
if (data == 200)
console.log("Data successfully sent to the server");
else
console.log("Error: Data cannot be sent to the server")
}
); }
}
}).data('gridster');
var localData = JSON.parse(localStorage.getItem('positions'));
if (localData != null) { $.each(localData, function (i, value) {
console.log('found positions'); console.log(value.col); console.log(value.row); console.log(value.size_x); console.log(value.size_y); var id_name;
id_name = "#"; id_name = id_name + value.id;
$(id_name).attr({ "data-col": value.col, "data-row": value.row, "data-sizex": value.size_x, "data-sizey": value.size_y });
}); } else {
console.log('No data stored in the local storage. Continue with the default values'); }
});