This is a migrated thread and some comments may be shown as answers.

How to access column name from column template?

4 Answers 980 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cosmin
Top achievements
Rank 1
Cosmin asked on 02 Aug 2012, 10:02 AM
Hello,

I have the following issue:

My data for a row looks like this (simplified):

{ Name: 'name', Statuses: [ {Name: 'StatusA', Value: 'ValueA'} , {Name:'StatusB', Value: 'ValueB'}] }

So on each row data I have a list of name-value collection for statuses.
I have a number of columns (one for each status) named with the status name: StatusA, StatusB, etc.

In the column template I want to put the value of the status depending on the column name.
I can access data.Statuses in the template and get the status values, but the template is not aware for which column is being rendered.

Is there any way to access the column name in the template or send it as a parameter?

Any help is appreciated!

4 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 06 Aug 2012, 08:30 AM
Hello Cosmin,

You can use jQuery.proxy to inject context for the function generated by kendo.template and access that additional data inside the template through this.

See the following fiddle for more details: http://jsfiddle.net/hG6zR/

All the best,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ketul
Top achievements
Rank 1
answered on 14 Oct 2016, 03:50 PM
[quote]Nikolay Rusev said:
You can use jQuery.proxy to inject context for the function generated by kendo.template and access that additional data inside the template through this.
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 

[/quote]

Do you know how can I achieve something like this in Angular Widget, See the example at http://dojo.telerik.com/uVAbu/2, In the below code block see the "template" and I would like to access the column object within {{ myHelper(dataItem.FirstName) }}

columns: [{
               field: "FirstName",
               title: "First Name",
             template: "this is template <span>{{ myHelper(dataItem.FirstName) }}</span>",
               width: "120px"
               }

 

0
Nikolay Rusev
Telerik team
answered on 17 Oct 2016, 07:56 AM

Hello ketul,

There isn't exact analogue for Angular. One way to go is to pass column index in the helper function. See example for it - http://dojo.telerik.com/@rusev/okiLO

Regards,
Nikolay Rusev
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Ketul
Top achievements
Rank 1
answered on 17 Oct 2016, 08:55 AM
Thanks Nioklay, I think that works as, based on the index I can access the column object.
Tags
Grid
Asked by
Cosmin
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Ketul
Top achievements
Rank 1
Share this question
or