When I am loading a saved layout, if the layout has a height larger than what is already loaded on the page at $('.grid-stack').attr('data-gs-current-height'), the elements with a y-axis which goes over that load at the top position of the page. Their y-axis labels are reflected correctly in the DOM.
If the height of the document does not change, it works as intended. This only occurs when the newly loaded widgets have a greater combined height than the document they are being loaded into.
I have used the following code to change both the ('.grid-stack').attr('data-gs-current-height') value and the height of the element value prior to loading the widget, but they still render the same stacked on top of one another although the data-gs-current-height does show it has updated prior to loading the widgets new values in the DOM.
The code I use for changing the grid stack height is:
var changeGridStackHeight = function(gridStackHeight, docHeight, json){
$('.grid-stack').attr("data-gs-current-height", gridStackHeight);
$('.grid-stack').css('height', docHeight);
loadUserTemplate(json);
};
and loadUserTemplate(json) is:
var loadUserTemplate = function(json){
var firstArray = json[0];
var parsed = (JSON.parse(firstArray));
var gridStack = $('.grid-stack-item');
var plength = parsed.length;
gridStack.each(function(index){
var count = 0;
var gridstackId = $(this).attr('data-custom-id');
for(var i=0; i < plength; i++){
if($(this).attr('data-custom-id') === parsed[i].id){
$(this).attr('data-gs-x', parsed[i].x);
$(this).attr('data-gs-y', parsed[i].y);
$(this).attr('data-gs-width', parsed[i].width);
$(this).attr('data-gs-height', parsed[i].height);
}
var equals = Number(parsed[i].id) == Number(gridstackId);
if(equals === true){
count++;
}
}
if(count === 0){
$(this).css('display', 'none');
}
});
var reposition = window.setTimeout(function(){
fixSizes();
},1000);
};