DropDownList in kendo grid control (by ClientTemplate)

為{幸葍}努か 提交于 2019-12-11 03:28:44

问题


I need to make behavor for ClientTemplate like we have for EditorTemplateName. So I want to make something like this:

Template:

@(
     Html.Kendo().DropDownListFor(m => m)        
            .BindTo((SelectList)ViewData["ExamResults"])
                .Template("#:Value# #:Text#")
                .DataTextField("Text")
                .DataValueField("Value")
            .Events(e => e
                .Change("examResultOnDropDownChange")
                .Open("examResultOnOpen"))
 )

And adding column into grid: .EditorTemplateName("ExamResultGridForeignKey")

but I want to: .ClientTemplate("ExamResultGridForeignKey") or something like that (but it doesnt work):

.ClientTemplate(
                Html.Kendo()
                    .DropDownList()
                    .Name("#=Id#")
                    .BindTo((SelectList)ViewData["ExamResults"])
                    .Template("#:Value# #:Text#")
                    .DataTextField("Text")
                    .DataValueField("Value")
 )

All that I need to make field with DropDownList in not editable mode (when we display value) looks like editable DropDownList.


回答1:


This is how my dropdown list is being rendered. IsInForecast is a bool field. All the If else is doing is having the correct ddl value (true/false) selected based on the value of the IsInForecast property. You're gonna have to tweak it to your needs.

columns.Bound(m => m.IsInForecast).Title("Is Forecasted").ClientTemplate(

   "# if (IsInForecast == true) { #" +

                          "<select id='#= OrderId #' onchange=save('#= OrderId #'); style='Width: 80px; color: 'navy' > " +
                            "<option id='yes' selected value='1'>Yes</option>" +
                            "<option id='no' value='0'>No</option>" +

                            "</select>" +
                     "# } else { #" +
                          "<select id='#= OrderId #' onchange=save('#= OrderId #'); style='Width: 80px; color: 'navy' > " +
                            "<option id='yes'  value='1'>Yes</option>" +
                            "<option id='no' selected value='0'>No</option>" +
                         "# } #" 
            );             

Where you see "<select id='#= OrderId #' that is setting the ddl ID field to so you know which dropdownlist/record you are editing. onchange=save('#= OrderId #'); is calling a JS function that passes the model property OrderId to the method. To get the selected value of correct ddl you just changed you can do this.

save(orderId) function{
  var ddl = # + orderId;
  var getSelectedValue = $(ddl).val();
}  

This will render a standard DDL. You can check out the documentation here

 http://demos.telerik.com/kendo-ui/web/grid/editing-custom.html


来源:https://stackoverflow.com/questions/23217890/dropdownlist-in-kendo-grid-control-by-clienttemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!