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

Error when serialize, idea? #104

Open Falcula opened 11 years ago

Falcula commented 11 years ago

Hi,

Just started to use Gridster. Iam trying to serialize down the state of the grid and save it into database. But when i run the serialize action i get the following error, anyone have any idea?

CODE!

var layout;
var grid_size = 100;
var grid_margin = 5;
var block_params = {
    max_width: 6,
    max_height: 6
};
$(function () {

    layout = $('.layouts_grid ul').gridster({

        widget_margins: [grid_margin, grid_margin],
        widget_base_dimensions: [grid_size, grid_size],

        serialize_params: function ($w, wgd) {
            return {
                x: wgd.col,
                y: wgd.row,
                width: wgd.size_x,
                height: wgd.size_y,
                id: $($w).attr('data-id'),
                name: $($w).find('.block_name').html(),
            };
        },
        min_rows: block_params.max_height
    }).data('gridster');

    // Temp test code!
    var tmp = layout.serialize();
    layout.add_widget(tmp, 4, 2); });

ERROR in jquery-v1.7.1

NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild] [Stanna vid fel]

fragment.appendChild( ret[i] );

schreyers commented 11 years ago

I found some issues when trying to do the same thing. When i did alerts of all the data i wanted to save it was all fine but once i passed it to where i wanted to save it, the data didn't pull through.

I ended up building seperate arrays for the position and then using them to save the coords into the database.

Hope that helps!