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

Can't serialize widget HTML text #292

Open centinel3 opened 10 years ago

centinel3 commented 10 years ago

I can't seem to figure out how to parse the serialized gridster object so that I can access the HTML text that goes with it. I can get all teh row/col/size_x,size_y values back, though anything within the

  • Cant' get this HTML
  • I can't seem to repopulate once I serialize gridster and try and repopulate the grid.

    Some of my code is below. Any help on this would be appreciated (or a push in the right direction if serialize doens't also grab the HTML (though believe it does).

    Working, though not adding the text within the widgets.

    // Instantiate gridster with params $(".gridster ul").gridster({ widget_margins: [10, 10], widget_base_dimensions: [200, 200], 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 }; } });

            // Creates API object 
            var gridster = $(".gridster ul").gridster().data('gridster');
    
            // serialize the grid
            var serialization;
            $('#serialize').on('click', function () {
                serialization = JSON.stringify(gridster.serialize());
                //alert(serialization);
            });
    
            // Rebuild grid from serialization
            $('#rebuild-grid').on('click', function () {
                gridster.remove_all_widgets();
                var parsedSerializedData = JSON.parse(serialization);
                $.each(parsedSerializedData, function (i,value) {
    
                    var idName;
                    idName = '#';
                    idName = idName + value.id;
    
                    //$(id_name).attr({ 'data-col': value.col, 'data-row': value.row, 'data-sizex': value.size_x, 'data-sizey': value.size_y });
                    gridster.add_widget('<li>' + idName + '</li>', value.size_x, value.size_y, value.col, value.row);
                });
            });