Reputation: 359
I have created columns dynamically in the kendo ui grid. The data displayed in the columns could be date , string integer, hyperlinks or any other type.
Data in the column can be integer/hyperlink at the same time. Means for a particular record the data in column can be integer. For next record same column can have a hyperlink value. I have created fields and added that in the grid.
How can I do this.
Upvotes: 1
Views: 7559
Reputation: 707
You can always set a function against the template of the column you wish to format and conditionally return the content of what you want to appear.
This could look something like this:
var dataSource = new kendo.data.DataSource({
data: [
{ Id:1, val: "value" },
{ Id:"http://google.com", val: "another value" }
]
});
$(function () {
$("#grid").kendoGrid({
columns: [
{
field: "Id",
template: function (dataItem) {
if (typeof dataItem.Id == "string") {
return "<a href=\"" + dataItem.Id + "\">" + dataItem.Id + "</a>";
} else {
return dataItem.Id;
}
}
}],
dataSource: dataSource
});
});
Upvotes: 1