Gridstack.js: export position as json

Created on 1 Aug 2018  ·  3Comments  ·  Source: gridstack/gridstack.js

@hairyheron
hi,
how to i can export current position as JSON format, then show by this json.

question

Most helpful comment

If you want to persist layout of gridstack on the page, here is a short example:

var getGridJSON = function () {
    var nodes = $('#gridstack').data('gridstack').grid.nodes;
    return nodes.map(function(obj, idx){
       return {
           x: obj.x,
           y: obj.y,
           width: obj.width,
           height: obj.height,
           minHeight: obj.minHeight,
           minWidth: obj.minWidth
       }
    });
};
// this will give you array with each gridstack item, stringify it and persist in the backend :)
console.log(getGridJSON());

All 3 comments

I am not a maintainer of this project. Even if I were, I do not understand your question.

If you want to persist layout of gridstack on the page, here is a short example:

var getGridJSON = function () {
    var nodes = $('#gridstack').data('gridstack').grid.nodes;
    return nodes.map(function(obj, idx){
       return {
           x: obj.x,
           y: obj.y,
           width: obj.width,
           height: obj.height,
           minHeight: obj.minHeight,
           minWidth: obj.minWidth
       }
    });
};
// this will give you array with each gridstack item, stringify it and persist in the backend :)
console.log(getGridJSON());

Thanks, @zhanazhan . That looks like a good solution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

javayoung picture javayoung  ·  3Comments

athamsnajeeb1 picture athamsnajeeb1  ·  7Comments

ascendantofrain picture ascendantofrain  ·  6Comments

saroque picture saroque  ·  4Comments

alissondiel picture alissondiel  ·  6Comments