I have a object that looks like this:
"employees":[
{"lastName":"Doe"},
{"firstName":"Anna" },
{"firstName":"Peter", "lastName":"Jones"}
]
As you can see sometimes one of the properties is missing, sometimes lastname may be missing and other times firstname is missing.
The problem is when I use kendo grid (Jquery UI) because defining the columns I set something similar
$("#grid").kendoGrid({
columns: [{
field: "firstName",
title: "Firstname",
template: "Firstname: #:firstName#"
},{
field: "lastName",
title: "Lastname"
template: "Lastname: #:lastName#"
}
Because sometime the firsname is NULL and the same with lastName. The problem comes in the template. So how can I handle this?
I am not able to edit the datasource because it comes from a external api.
Here is an exampleof the replicated issue: https://dojo.telerik.com/uPUdiYOC
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2021.2.616/styles/kendo.default-v2.min.css"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2021.2.616/js/kendo.all.min.js"></script>
</head>
<body>
<div id="grid"></div>
<script>
$("#grid").kendoGrid({
columns: [ {
field: "firstName",
template: "<strong>#: firstName # </strong>"
}],
dataSource: [ {"lastName":"Doe"},
{"firstName":"Anna" },
{"firstName":"Peter", "lastName":"Jones"} ]
});
</script>
</body>
</html>