Scrollable Kendo Grid
A KendoUI grid with a scrollable data area where the headers stay aligned.
by lhoeppner
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="grid"></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,
"IsEditable": true
}, {
"ProductID": "1",
"ProductName": "name1",
"UnitPrice": 7.5,
"Qty": 1,
"IsEditable": false
},
]
};
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"
}
];
$("#grid").kendoGrid({
dataSource: dataSource,
height: "300px",
columns: columns,
editable: true,
edit: function (e) {
var fieldName = e.container.find("input").attr("name");
if (fieldName === "ProductID" && !isEditable(e.model)) {
this.closeCell();
}
}
});
function isEditable(model) {
// default to editable if no IsEditable attribute
return !model.hasOwnProperty("IsEditable") || model.IsEditable;
}