Reputation: 51
i've done some test with gridster and i can save some gridster data, like coords, size, ids etc.
But i'm unnable to save content of the divs who populate gridster in a way i can load later along with gridster coords for each element.
Here is my code:
<script type="text/javascript">
$(document).ready(function () {
var grid_canvas = $("#homepage > #grid").gridster({
widget_margins: [10, 10],
widget_base_dimensions: [140, 140],
widget_selector: ".gs_w",
shift_larger_widgets_down: false,
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) {
var positions = JSON.stringify(this.serialize());
$.post(
"process.php",
{portlets: positions},
function(data){
var resultado = jQuery.parseJSON(data);
$("#result").html(resultado)
}
);
}
}
}).data('gridster');
});
</script>
</head>
<body>
<div id="homepage">
<div id="grid" style="height: 480px; position: relative; width:480px; ">
<div id="protlet-1" data-row="1" data-col="1" data-sizex="1" data-sizey="1" class="gs_w"><div>Test-one</div></div>
</div>
</div>
<div id="result"></div>
Here my process.php:
<?php echo $_POST["portlets"];?>
I can extract all but html content of that div to recreate dynamically later.
Can anyone help me?
Thank you
Upvotes: 5
Views: 5032
Reputation: 616
when doing serialize_params,capture the html content as well. Here is a simple example showing the same.
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,
htmlContent : $($w).html()
};
}
When you iterate over the JSON, you will have to construct the structure. And then invoke gridster method.
Upvotes: 6