How to access column name from column template?

5 posts, 1 answers
  1. Cosmin
    Cosmin avatar
    2 posts
    Member since:
    Jun 2012

    Posted 02 Aug 2012 Link to this post

    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!
  2. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 06 Aug 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Ketul
    Ketul avatar
    2 posts
    Member since:
    Jun 2008

    Posted 14 Oct in reply to Nikolay Rusev Link to this post

    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!
     

    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"
                   }

     

  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 17 Oct Link to this post

    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.
     
  6. Ketul
    Ketul avatar
    2 posts
    Member since:
    Jun 2008

    Posted 17 Oct in reply to Nikolay Rusev Link to this post

    Thanks Nioklay, I think that works as, based on the index I can access the column object.
Back to Top
Kendo UI is VS 2017 Ready