Scrollable Kendo Grid
A KendoUI grid with a scrollable data area where the headers stay aligned.
by interscape
HTML
<script src="http://cdn.kendostatic.com/2012.1.322/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.default.min.css">
<div style="width: 300px; overflow: hidden;">
<div id="grid1"></div>
</div>
CSS
html
{
font:12px sans-serif;
}
JavaScript
var dataSource = {
data: [
{
"ProductID": "1",
"ProductName": "name1",
"UnitPrice": 7.5,
"Qty": 1},
{
"ProductID": "1",
"ProductName": "name1",
"UnitPrice": 7.5,
"Qty": 1},
{
"ProductID": "1",
"ProductName": "name1",
"UnitPrice": 7.5,
"Qty": 1},
]
};
var columns = [
{
field: "ProductID",
title: "Product Id",
width: "90px"},
{
field: "ProductName",
title: "Product Name",
width: "150px"},
{
field: "UnitPrice",
title: "Unit Price",
format: "{0:c}",
width: "70px"},
{
field: "Qty",
title: "Qty",
width: "70px"}
];
$("#grid1").kendoGrid({
dataSource: dataSource,
height: "300px",
columns: columns,
pageable: true
});
$("#grid1 .k-grid-header-wrap").css("overflow", "hidden");
$("#grid1 .k-grid-content").css("overflow-y", "scroll").css("overflow-x", "auto").scroll(function() {
var left = $(this).scrollLeft();
var wrap = $("#grid1 > .k-grid-header-wrap");
if (wrap.scrollLeft() != left) wrap.scrollLeft(left);
});