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.03k stars 1.2k forks source link

build gridster based on saved positions #235

Closed josh4car closed 11 years ago

josh4car commented 11 years ago

So I have serialize_params saving to a database...great. How do I then use my saved array to build the actual gird on page load? Any suggestions?

My code:

  var gridster = $(".gridster ul").gridster({
    widget_margins: [5, 10],
    widget_base_dimensions: [150, 160],
    min_cols: 2,
    max_cols: 6,
    serialize_params: function($w, wgd) {
        return {
            id: wgd.el[0].id,
            col: wgd.col, 
            row: wgd.row,
            size_x: wgd.size_x,
            size_y: wgd.size_y
        };
    },
    draggable: {
        handle: '.handle',
        stop: function(event, ui) {

        var positions = JSON.stringify(gridster.serialize());

        $.ajax({
            url : ROOT + '_ajax/save_ad_dash_cards.php',
            data : {'cards' : positions},
            type : 'POST',
            success : function(data) {

                console.log(data);
            }
        });
      }
    }
}).data('gridster'); 
vieron commented 11 years ago

http://gridster.net/demos/grid-from-serialize.html