$(function () {
$('.grid-stack').gridstack({});
$('#grid').on('gsresizestop', function(event, elem) {
// this shows it's being called 6 times with 'undefined' elem for nested 1-6 items,
// plus 1 for actual top item being resized!
var newHeight = $(elem).attr('data-gs-height');
console.log(newHeight);
// force nested grid to fill in all the parent gridItem content height
// just like it already does the width (% column based)
// height = rows * (cellHeight + verticalMargin) - verticalMargin (as last row doesn't have margin)
// so
// cellHeight = (height - (rows-1) * verticalMargin) / rows;
elem = $(elem);
if (elem && elem.is('#nestedGridParentItem')) {
var gridEle = $('#nestedGrid');
var grid = gridEle.data('gridstack');
var height = gridEle.parent().innerHeight();
var rows = grid.grid.getGridHeight();
var verticalMargin = grid.verticalMargin();
if (rows < 1) { rows = 1; }
var oldCellHeight = grid.cellHeight();
var cellHeight = (height - (rows-1) * verticalMargin) / rows;
grid.batchUpdate();
grid.cellHeight(cellHeight);
grid.commit();
// which has no immediate effect because of this in GridStack.prototype._updateStyles()
// if (this._styles._max !== 0 && maxHeight <= this._styles._max) { return; } // Keep this._styles._max increasing
}
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.