1

So i have a Kendo UI grid and i have one column that is a int

basically have a int column and

1 means good, 2 means best, 3 means top,

Its kind of thing that a Enum would be the right thing to use but i cant (internal business rules) so i need to make a custom drop down that will replace the number

there are 2 ways to do it in mvc

one is to use a EditorTemplateName and the other one is to use a ForeignKey

the problem is that EditorTemplateName only works in edit mode and displays the number in display mode, and ForeignKey only works in display mode and displays the number in edit mode

CMS
  • 3,657
  • 1
  • 27
  • 46
  • Have you seen this? http://stackoverflow.com/questions/11116542/how-can-i-set-and-get-the-value-of-a-dropdownlist-in-a-grid-in-kendo-ui-mvc – Steve Greene Aug 05 '15 at 20:07
  • 1
    ok i see that he is using there a ClientTemplate but when i made client template ".ClientTemplate("#: Text #");" the text in the cell shows "function Text() { [native code] }" – CMS Aug 05 '15 at 20:27

2 Answers2

0

ok after some hard work here is what i came up with

i used a ClientTemplate together with EditorTemplateName

columns.Bound(c => c.Condition)
.EditorTemplateName("_ConditionDropDown")
       .ClientTemplate("# if (Condition=== 1) {#" +
                    "good" +
                "#} else if (Condition=== 2) {#" +
                    "best" +
                "#} else if (Condition=== 3) {#" +
                    "top" +
                "#}#");

And It Works as i needed


i decided to add the template i used it might help someone

@{
    ViewBag.ConditionDropDownList = new List<SelectListItem>()
                {
                    new SelectListItem { Value="0", Text="- All Conditions -" },
                    new SelectListItem { Value="1", Text="good" },
                    new SelectListItem { Value="2", Text="best" },
                    new SelectListItem { Value="3", Text="top" }
                };
}

@(Html.Kendo().DropDownList()
              .Name("Condition")
           .DataTextField("Text")
           .DataValueField("Value")
               .BindTo((System.Collections.IEnumerable)ViewBag.ConditionDropDownList)
               .Value("0")
)
CMS
  • 3,657
  • 1
  • 27
  • 46
0

this way will work sometimes, if not the second answer will.

A dropdownlist should be used by default for the foreignkey column. If a dropdownlist is not used in your project then this indicates that the GridForeignKey editor template is missing from the EditorTemplates folder. If that is the case the you should copy the editor from the [Installation folder] > wrappers > aspnetmvc > EditorTemplates > razor folder to the EditorTemplates folder in your project.

CMS
  • 3,657
  • 1
  • 27
  • 46