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

[Solved] Column Client Template that refers to another column's value.

2 Answers 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matt
Top achievements
Rank 1
Matt asked on 30 Nov 2011, 11:24 PM
Hello,

I'm putting together a demo evaluating the Telerik controls, and I'm trying to define a grid column that has a template that depending on the value of that column displays one of two images.  I want to include the value from another column as an attribute for later use in the image's click handler, but am receiving a javascript error if I refer to any column other than the current one in the template.  Here is what I am doing:

cols.Bound(c=> c.LabelCount).
                ClientTemplate("<# if (LabelCount > 0)"
                + " { return '<img src=\"..."\" onclick=\"LabelClicked(this)\"  EntryId = \"<#= Id #>\"  />'; } else "
                + "{ return '<img src=\"...(disabled version)"\"    />'; } #>")

This gives me an Invalid character  error from telerik.grid.min.js however.  If I replace <#= Id #>
 with <#= LabelCount #> everything works fine(except for not giving me the data I want).  I've tried prefixing Id with c. and dataItem. with no success.  What's the proper way to do this, or if it's impossible for some reason how can I achieve clicking the image calling a javascript function with another columns value as a parameter?  I'm using MVC Q3 2011.



2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 01 Dec 2011, 10:27 AM
Hi Matt,

Try this:

ClientTemplate("<#= getImage(LabelCount, Id) #>")


<script>

function getImage(labelCount, id) {
    if (labelCount > 0) {
          return '<img src=".."'>';
    } else {
          return '<img src=".."'>';
     }
}

</script>

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Matt
Top achievements
Rank 1
answered on 01 Dec 2011, 05:16 PM
Worked perfectly.  Thanks very much!
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Matt
Top achievements
Rank 1
Share this question
or