This article is an example of the Kendo Grid Component with a frozen row. The framework used is the Kendo UI for jQuery. In this example, our requirement is to freeze a row at the top of the grid. This is based on the https://docs.telerik.com/kendo-ui/knowledge-base/grid-frozen-rows example. Unfortunately, as of this writing, the grid does not produce the expected result when adding the following options:
- Resizable columns.
- Group by column.
- Show/hide columns.
- Filter by column.
Here is our solution. You can edit the code below using any text editor but I prefer Visual Studio Code. Make sure you are connected to the Internet because the code pulls the Kendo library from the Telerik CDN. Take note that this is just a demonstration code and you'll need to purchase a license if you are going to use Kendo UI for jQuery for more than just evaluation purposes.
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Kendo Grid Frozen Row Example</title> | |
<link rel="stylesheet" | |
href="https://kendo.cdn.telerik.com/2021.1.224/styles/kendo.default-v2.min.css"/> | |
<script src="http://code.jquery.com/jquery-3.5.1.min.js"></script> | |
<script src="https://kendo.cdn.telerik.com/2021.1.224/js/kendo.all.min.js"></script> | |
</head> | |
<body> | |
<style> | |
.frozen-row, | |
.k-alt.k-master-row.frozen-row { | |
font-weight: bold; | |
font-size: 0.9em; | |
background-color: #bde0ed; | |
} | |
</style> | |
<div id="example"> | |
<div id="grid"></div> | |
<script> | |
$(document).ready(function () { | |
$("#grid").kendoGrid({ | |
dataSource: { | |
data: [ | |
{ | |
reference: "001", | |
name: "Ragnar", | |
description: "Lothbrok", | |
}, | |
{ | |
reference: "002", | |
name: "Ivar", | |
description: "The boneless", | |
}, | |
{ | |
reference: "003", | |
name: "Bjorn", | |
description: "Ironside", | |
}, | |
{ | |
reference: "004", | |
name: "Rollo", | |
description: "", | |
}, | |
{ | |
reference: "005", | |
name: "Lagertha", | |
description: "", | |
}, | |
{ | |
reference: "006", | |
name: "Aslaug", | |
description: "", | |
}, | |
{ | |
reference: "007", | |
name: "Torvi", | |
description: "Ironside", | |
}, | |
{ | |
reference: "008", | |
name: "Siggy", | |
description: "Haraldson", | |
}, | |
] | |
}, | |
height: 250, | |
sortable: true, | |
resizable: true, | |
groupable: true, | |
columnMenu: true, | |
filterable: true, | |
columns: [{ | |
field: "reference", | |
title: "Reference", | |
}, { | |
field: "name", | |
title: "Name" | |
}, { | |
field: "description", | |
title: "Description" | |
}], | |
dataBound: function(e) { | |
var grid = e.sender; | |
var items = grid.items(); | |
grid.element.height(grid.options.height); | |
var $table = grid.element.find(".k-grid-header table"); | |
var $frozenRow = $table.find(".frozen-row"); | |
items.each(function() { | |
var $row = $(this); | |
var dataItem = grid.dataItem($row); | |
if (dataItem.reference === "005") { | |
if ($frozenRow.length === 0) { | |
// no frozen row yet, let's add one | |
var $item = $row.clone(); | |
$item.addClass("frozen-row"); | |
$table.append($item); | |
grid.element.height(grid.element.height() | |
+ $row.height()); | |
} | |
$row.hide(); | |
} | |
}); | |
}, | |
columnHide: function(e) { | |
var $table = e.sender.element | |
.find(".k-grid-header table"); | |
var $frozenRow = $table.find(".frozen-row"); | |
$frozenRow.find('[data-field="' | |
+ e.column.field + '"]').hide(); | |
}, | |
columnShow: function(e) { | |
var $table = e.sender.element | |
.find(".k-grid-header table"); | |
var $frozenRow = $table.find(".frozen-row"); | |
$frozenRow.find('[data-field="' | |
+ e.column.field + '"]').show(); | |
}, | |
group: function(e) { | |
var $table = e.sender.element | |
.find(".k-grid-header table"); | |
var $frozenRow = $table.find(".frozen-row"); | |
$frozenRow.remove(); | |
}, | |
}); | |
}); | |
</script> | |
</div> | |
</div> | |
</body> | |
</html> |
The main difference here is our target row (frozen row) is appended to the table
instead of the thead
element. We also handle the columnHide
and columnShow
events to hide/show the frozen row's cell. And when a column is grouped, we remove the frozen row so that on dataBound
, it is recreated. Recreating it aligns the columns.
For this example, Reference 005 is the target row. At the start, you will see something like this:
![]() |
Kendo Grid Frozen Row |
Try sorting, grouping, hiding/showing columns, and filtering. Our target row remains where it is supposed to be.
![]() |
Kendo Grid Frozen Row Grouped by Column |
![]() |
Kendo Grid Frozen Row Sorted Column |
![]() |
Kendo Grid Frozen Row Resized Column |
There you have it. A quick and simple example of how to use the Kendo Grid with a frozen row.