Reputation: 2227
How can i get available height in kendo grid ? That means I am adding items dynamically to the grid, So i need height of the grid dynamically
Upvotes: 1
Views: 2745
Reputation: 40887
You can query it by asking the height
of the wrapper
(full grid) or tbody
(inner body of the grid) depending what you want:
// Get a reference to the KendoUI Grid object
var grid = $("#grid").data("kendoGrid");
// Ask the height of the Grid
alert("Height of Grid: " + grid.wrapper.height())
// Ask the height of the body (total rows) of the Grid
alert("Height of the body of the Grid: " + grid.tbody.height());
Important: the body of the grid might be greater than the Grid itself if part of the rows are hidden and you have to scroll to see them.
Example.
$(document).ready(function() {
$("#show").on("click", function() {
var grid = $("#grid").data("kendoGrid");
alert("Grid: " + grid.wrapper.height() + "\n" +
"Body: " + grid.tbody.height());
});
$("#grid").kendoGrid({
dataSource: {
data: products,
schema: {
model: {
fields: {
ProductName: { type: "string" },
UnitPrice: { type: "number" },
UnitsInStock: { type: "number" },
Discontinued: { type: "boolean" }
}
}
},
pageSize: 20
},
pageable: true,
height: 300,
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "130px" },
{ field: "UnitsInStock", title: "Units In Stock", width: "130px" },
{ field: "Discontinued", width: "130px" }
]
});
});
html { font-size: 12px; font-family: Arial, Helvetica, sans-serif; }
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.common.min.css" />
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.default.min.css" />
<script src="http://cdn.kendostatic.com/2014.3.1316/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.3.1316/js/kendo.all.min.js"></script>
<script src="http://demos.telerik.com/kendo-ui/content/shared/js/products.js"></script>
<button id="show" class="k-button">Show</button>
<div id="grid"></div>
Upvotes: 3