I created another solution that works when your html is different in the sense that its not just the grid alone but other content above it. The JSFiddle is located here.
HTML
<div class="container">
<div class="test">
hey there
</div>
<div id="grid"></div>
</div>
CSS
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
.container{
height:100%;
}
.test{
height:100px;
}
html {
overflow: hidden;
}
JS
function resizeGrid() {
var gridElement = $("#grid");
var dataArea = gridElement.find(".k-grid-content");
var newHeight = gridElement.parent().innerHeight() - 2 -calcHeightsOfParentChildren(gridElement);
var diff = gridElement.innerHeight() - dataArea.innerHeight();
if((newHeight-diff)>0){
gridElement.height(newHeight);
dataArea.height(newHeight - diff);
}
}
function calcHeightsOfParentChildren(element){
var children = $(element).parent().children();
var height = 0;
$.each(children, function( index, value ) {
if($(value).attr("id") != $(element).attr("id")){
height = height + $(value).height();
}
});
return height;
}
$(window).resize(function() {
resizeGrid();
});
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "http://demos.kendoui.com/service/Northwind.svc/Orders"
},
schema: {
model: {
fields: {
OrderID: {
type: "number"
},
ShipName: {
type: "string"
},
ShipCity: {
type: "string"
}
}
}
},
pageSize: 10,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
height: 250,
filterable: true,
sortable: true,
pageable: true,
dataBound: resizeGrid,
columns: [{
field: "OrderID",
filterable: false
},
"ShipName",
"ShipCity"
]
});
The key in my solution is the modified resizeGrid function. What happens without this modification is if the user scrolls far enough upwards the bottom pager gets lost! By checking to make sure the newHeight-diff is greater than 0 it prevents this error.
Second calcHeightsOfParentChildren when passed the element of the grid in question will calculate all the other heights except its own to help calculate the correct difference to place the pager control and grid so that it truly takes up 100% and retains its 100% ratio.