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

Display value in grid column based on conditional

1 Answer 1380 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Millie
Top achievements
Rank 1
Millie asked on 16 Sep 2013, 03:04 PM
I have a hierarchy Grid. The child grid has complex values used to define the columns. I need to do a conditional when defining what to display in the "Value" column. "Value" is of type NotificationEventConditionValueViewModel, which is defined as:


public class NotificationEventConditionValueViewModel
{
public string ValueString { get; set; }
public System.DateTime ValueDate { get; set; }
public bool ValueBoolean { get; set; }
}

In my child grid I am trying to do a conditional based on the type of Value, something like the following:

columns.Bound(e => e.Value).Title("Value").ClientTemplate("\\#if(NotificationEventConditionField.FieldType.Id == 5){\\#=Value.ValueBoolean\\#}else{\\#=Value.ValueString\\#}\\#").Width(80).HeaderHtmlAttributes(new { style = "font-weight: bold;text-decoration: underline;" });

The
"\\#if(NotificationEventConditionField.FieldType.Id == 5) evaluates fine, but the
{\\#=Value.ValueBoolean\\#} does not show the value I want, instead it show the string: #=Value.ValueBoolean.

Can you please help me to determine what I am doing wrong in the syntax. I am attaching some files. In the COnfigure.cshtml look for Grid "UDEGrid_#=Id#" which is the child grid, and Grid "notificationGridUDE" which is the parent grid. A am also attaching the view models.
Thank yoy very much in advance.

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 18 Sep 2013, 07:52 AM
Hi Millie,

The template syntax which you use is slightly incorrect. Please try to work with the ternary operator as in this way the syntax will be much simpler.
.ClientTemplate("\\#= (NotificationEventConditionField.FieldType.Id == 5) ? Value.ValueBoolean : Value.ValueString \\#")

Please test the solution and let me know if it fits in your scenario.
Thank you in advance.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Millie
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or