Adding a Kendo UI Grid as a widget to any Rollbase page is easy. In this blog, we'll show you how to generate a responsive grid that fits any screen size.
Rollbase provides out-of-the-box, no-code rendering for lists of objects using Kendo UI Grids. That is, as soon as you declare an object using point-and-click, drag-and-drop methodology, you get an auto-generated UI with very powerful grid control. But how would you go about showing a Kendo UI Grid containing, for example, data from multiple objects or a grid that you would like to tailor to your custom needs?
In this post, we'll show you how to easily add a Kendo UI Grid as a widget in any Rollbase page. You will also see the additional benefits you get out of the box when the custom grid is part of the page cells.
Here is how we need to proceed, we will do the work from the page designer:
That's all there is to it. Here is the JavaScript code to achieve this:
01.
<div id=
"grid"
style=
"width:100%;"
></div>
02.
<script>
03.
rb.newui.util.addEventListener(
"rbs_pageRender"
,
function
() {
04.
function
buildData(values) {
05.
var
gridData = [];
06.
if
(values) {
07.
for
(
var
i = 0; i < values.length; i++) {
08.
var
data = {
09.
name: values[i][0],
10.
class: values[i][1],
11.
age: values[i][2]
12.
}
13.
gridData.push(data);
14.
}
15.
generateKendoGrid(gridData);
16.
}
17.
}
18.
19.
function
generateKendoGrid(gridData) {
20.
var
dataSource =
new
kendo.data.DataSource({data: gridData});
21.
var
kendoGrid = $(
'#grid'
).kendoGrid({
22.
columns: [{
23.
field:
'name'
,
24.
title:
'Name'
,
25.
groupable:
false
//Let's make this field not groupable
26.
}, {
27.
field:
'age'
,
28.
title:
'Age'
29.
}, {
30.
field:
'class'
,
31.
title:
'Class'
32.
}],
33.
34.
groupable: { messages:
35.
{empty:
"Drag and Drop Age or Class Columns here for grouping"
}},
36.
dataSource: dataSource
37.
});
38.
}
39.
40.
// Access the data -> on callback, we will build data source
41.
rbf_selectQuery(
"SELECT name,Class,Age FROM Students"
, 200, buildData);
42.
});
43.
</script>
Now here is how it renders (with Material Black theme):
Even on a smartphone, the grid rendering looks good:
It is worth noting that since the Kendo UI Grid belongs to a section cell, we get a lot of benefits out of the box:
Here is an example where we have a responsive section with two columns. The left column has the student grid and the second column features a chart showing the number of students per class.
On desktop:
On tablet:
In summary, we saw how easy it is to render a Kendo UI Grid and add it to the no-code responsive system. We can apply the same technique to any widget and construct very creative and innovative pages, thanks to the rich set of Kendo UI widgets available. Stay tuned, we will write more blogs showing how to use other widgets like pivot grids and Gantt charts.
Check this blog for more details on how to create custom dashboards using Kendo UI Charts.
Thierry Ciot is a Software Architect on the Corticon Business Rule Management System. Ciot has gained broad experience in the development of products ranging from development tools to production monitoring systems. He is now focusing on bringing Business Rule Management to Javascript and in particular to the serverless world where Corticon will shine. He holds two patents in the memory management space.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites