简体   繁体   English

Kendo网格控件中的DropDownList(通过ClientTemplate)

[英]DropDownList in kendo grid control (by ClientTemplate)

I need to make behavor for ClientTemplate like we have for EditorTemplateName. 我需要像对待EditorTemplateName一样对ClientTemplate做出行为。 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") 并将列添加到网格中: .EditorTemplateName("ExamResultGridForeignKey")

but I want to: .ClientTemplate("ExamResultGridForeignKey") or something like that (but it doesnt work): 但我想: .ClientTemplate("ExamResultGridForeignKey")或类似的东西(但它不起作用):

.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. 我需要在不可编辑的模式下(当我们显示值时)使用DropDownList制作字段的所有事情看起来都像可编辑的DropDownList。

This is how my dropdown list is being rendered. 这就是我的下拉列表的呈现方式。 IsInForecast is a bool field. IsInForecast是一个布尔字段。 All the If else is doing is having the correct ddl value (true/false) selected based on the value of the IsInForecast property. If Isother所做的所有事情都是根据IsInForecast属性的值选择正确的ddl值(对/错)。 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. 您在其中看到"<select id='#= OrderId #'将ddl ID字段设置为"<select id='#= OrderId #' ,以便知道正在编辑的下拉列表/记录onchange=save('#= OrderId #');调用JS函数它将模型属性OrderId传递给方法。要获得刚更改的正确ddl的选定值,可以执行此操作。

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

This will render a standard DDL. 这将呈现一个标准的DDL。 You can check out the documentation here 您可以在此处查看文档

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM