I have a column in a Kendo grid that I want to perform some specific logic for when rendering, and am using Angular. I have the grid columns set up using the k-columns directive.
After looking at the documentation, it seemed simple: I could add the template option to my column, define the function to perform my logic, and pass the dataItem value in. What I have looks something like this:
k-columns='[{ field: "Name", title: "Name",
template: function (dataItem){
// Perform logic on value with dataItem.Name
// Return a string
}
}]'
However, running this causes a syntax error complaining about the character '{' that forms the opening of the block in my function.
I have seen several examples of defining a template function in this format. Is there something else that needs to be done for this to work? Am I doing something incorrectly? Is there another way of defining the template as a function and passing the column data to it? (I tried making a function on my $scope, which worked, except I couldn't figure out how to get data passed into the function.)
Thank you for your help.
We will start by creating a sample grid, applying a simple template, and then move the generation of the content to render to a function that we will call from the template. Before we start we will create a simple Kendo UI grid sample using AngularJS, and then we will proceed to add templates to certain columns.
kendo:grid-pageable-messagesThe text messages displayed in pager. Use this option to customize or localize the pager messages.
Returns the data item to which the specified table row is bound. The data item is a Kendo UI Model instance.
template String|Function. The template which renders the column content. The grid renders table rows ( <tr> ) which represent the data source items. Each table row consists of table cells ( <td> ) which represent the grid columns. By default the HTML-encoded value of the field is displayed in the column.
This can be done via the columns.template
parameter by supplying a callback function whose parameter is an object representing the row. If you give the row a field named name
, this will be the property of the object you reference:
$("#grid").kendoGrid({
columns: [ {
field: "name",
title: "Name",
template: function(data) {
return data.name + "has my respect."
}
}],
dataSource: [ { name: "Jane Doe" }, { name: "John Doe" } ]
});
More information is available on Kendo's columns.template reference page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With