<link rel="stylesheet" href="http://cdn.kendostatic.com/2011.3.1407/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2011.3.1407/styles/kendo.default.min.css">
<script src="http://cdn.kendostatic.com/2011.3.1407/js/kendo.all.min.js"></script>
<!--Full article at http://wp.me/p4JH2A-I3 -->
<div id="header-content">This is a header, place where you usually add your menu</div>
<div id="main-content">
<h1>Top Section</h1>
<div id="grid"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ultricies sem ut metus elementum, nec cursus nulla dictum. Nam facilisis neque eu sodales ultricies. Pellentesque faucibus justo eget urna viverra, eget maximus lectus varius. Vivamus consectetur tellus at pulvinar finibus. Donec ipsum ligula, placerat in tincidunt in, sollicitudin sed ante. Maecenas eu urna elementum, porta sapien at, ornare lectus. Sed interdum magna at lectus aliquam imperdiet. Mauris ultrices erat a tincidunt pellentesque. Pellentesque sit amet lacinia nisi. Morbi sollicitudin, sapien congue eleifend rhoncus, sem est iaculis arcu, nec mattis turpis urna ac nisl. Duis eleifend vehicula convallis. Fusce est neque, efficitur vel rhoncus vitae, condimentum non risus. Ut consequat egestas dui, in condimentum arcu auctor ac. Morbi volutpat facilisis velit, quis faucibus dui dictum at. Etiam ullamcorper libero blandit blandit accumsan. Fusce sagittis justo nisl, et semper ipsum aliquam in.</p>
</div>
JavaScript
function resizeGrid() {
//Define Elements Needed
var header = $("#header-content");
var content = $("#main-content");
var grid = $("#grid");
//Other variables
var minimumAcceptableGridHeight = 250; //This is roughly 5 rows
var otherElementsHeight = 0;
//Get Window Height
var windowHeight = $(window).innerHeight();
//Get Header Height if its existing
var hasHeader = header.length;
var headerHeight = hasHeader ? header.outerHeight(true) : 0;
//Get the Grid Element and Areas Inside It
var contentArea = grid.find(".k-grid-content"); //This is the content Where Grid is located
var otherGridElements = grid.children().not(".k-grid-content"); //This is anything ather than the Grid iteslf like header, commands, etc
console.debug(otherGridElements);
//Calcualte all Grid elements height
otherGridElements.each(function () {
otherElementsHeight += $(this).outerHeight(true);
});
//Get other elements same level as Grid
var parentDiv = grid.parent("div");
var hasMainContent = parentDiv.length;
if (hasMainContent) {
var otherSiblingElements = content.children()
.not("#grid")
.not("script");
//Calculate all Sibling element height
otherSiblingElements.each(function () {
otherElementsHeight += $(this).outerHeight(true);
});
}
//Padding you want to apply below your page
var bottomPadding = 10;
//Check if Calculated height is below threshold
var calculatedHeight = windowHeight - headerHeight - otherElementsHeight - bottomPadding;
var finalHeight = calculatedHeight < minimumAcceptableGridHeight ? minimumAcceptableGridHeight : calculatedHeight;
//Apply the height for the content area
contentArea.height(finalHeight);
}
$(window).resize(function () {
resizeGrid();
});
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
...
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.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
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!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.