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

RadioButtons in ClientTemplate using an enum

1 Answer 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 15 May 2017, 02:47 PM

I have a grid in which one of the columns I would like to display/edit using RadioButtons.  The underlying value is an enum.  I'm still working on getting the column to display the correct choice.  Right now, none of the radio buttons are checked.  What am I doing wrong?  Below please see the grid, and the enum declaration (in case that's an issue)

 

@(Html.Kendo().Grid<HVMS.BusinessLayer.Models.Metric>()
    .Name("MetricGrid")
    .Columns(columns =>
    {
 
        columns.Bound(c => c.Name);
        columns.Bound(c => c.ThresholdAssignment).ClientTemplate(
            "<span>Unassigned</span> <input type='radio' name='Metrics[#= index(data)#].ThresholdAssignment'  # if (ThresholdAssignment == 'Unassigned') { # checked = 'checked' # } # />" +
            "  <span>Weekly</span> <input type='radio' name='Metrics[#= index(data)#].ThresholdAssignment'  # if (ThresholdAssignment == 'Weekly') { # checked = 'checked' # } # />" +
            "  <span>Monthly</span> <input type='radio' name='Metrics[#= index(data)#].ThresholdAssignment'  # if (ThresholdAssignment == 'Monthly') { # checked = 'checked' # } # />"
            );
 
    })
    .ToolBar(toolbar =>
    {
        toolbar.Save();
        toolbar.Excel();
        toolbar.Pdf();
    })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Navigatable()
    .Scrollable(s => s.Height("auto"))
    .Selectable(selectable => selectable
          .Mode(GridSelectionMode.Single)
          .Type(GridSelectionType.Row))
    .AutoBind(false)
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .Model(model => model.Id(p => p.Id))
        .Read(read => read.Action("Metrics_Read", "MetricThreshold").Data("additionalData"))
        .Update(update => update.Action("Metrics_Update", "MetricThreshold"))
 
    )
      )

 

public enum ThresholdAssignment { Unassigned, Weekly, Monthly }

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi
Telerik team
answered on 16 May 2017, 03:44 PM
Hi Michael,

I examined your code and your the cause if the error is the if statements where you check for the value of the Enumeration. You are comparing them as strings but actually they are integers. If you check if their value is their representative number your logic works as expected.

Please modify the code for the ClientTemplate as illustrated below and the error should disappear.


columns.Bound(c => c.ThresholdAssignment).ClientTemplate(
            "<span>Unassigned</span> <input type='radio' name='Metrics[#= index(data)#].ThresholdAssignment'  # if (ThresholdAssignment == 0) { # checked = 'checked' # } # />" +
            "  <span>Weekly</span> <input type='radio' name='Metrics[#= index(data)#].ThresholdAssignment'  # if (ThresholdAssignment == 1) { # checked = 'checked' # } # />" +
            "  <span>Monthly</span> <input type='radio' name='Metrics[#= index(data)#].ThresholdAssignment'  # if (ThresholdAssignment == 2) { # checked = 'checked' # } # />"
            );


 You can ensure that they have the right values by explicitly assigning them.


public enum ThresholdAssignment
{
   Unassigned = 0,
   Weekly = 1,
   Monthly = 2
}




Regards,
Georgi
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or