如何使用javascript绑定剑道网格单元

How to bind the kendo grid cell using javascript

本文关键字:网格 单元 绑定 何使用 javascript      更新时间:2023-09-26

我在应用程序中使用了剑道网格。在网格中,一行包含一个下拉列表。当我在下拉列表中选择值时,行中的其他单元格将更新。但我正在尝试使用javascript更新另一个单元格。我找不到解决这个问题的办法。

有人能帮我吗?

我的剑道网格在剃刀:

    @(Html.Kendo().Grid<models.employee>()
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(c => c.name).ClientTemplate(
                    "<input type='hidden' name='items[#= index(data)#].name' value='#= getLine(data)#' /> <p>#= getLine(data)#</p>"
                );
                columns.Bound(c => c.Emp_num).EditorTemplateName("EmpEditor").ClientTemplate(
                        "#= Emp_num #" +
                        "<input type='hidden' class='Emp-select' name='items[#= index(data)#].Emp_num' id='items[#= index(data)#].Emp_num' value='#= Emp_num #' />"
                    );
                columns.Bound(c => c.description).EditorTemplateName("DescripEditor").ClientTemplate(
                    "#= description #" +
                    "<input type='hidden' name='items[#= index(data)#].description' data-fill='items[#= index(data)#].description' value='#= description #' />"
                );
columns.Bound(c => c.address).EditorTemplateName("addressEditor").ClientTemplate(
                "#= address #" +
                "<input type='hidden' name='items[#= index(data)#].address' value='#= address #' data-fill='items[#= index(data)#].address' value='' />"
            );
    })

在EmpEditor.cshtml:中

@(Html.Kendo().DropDownList()
    .Name("Emp_num")
    .OptionLabel("Select Employee Number...")
    .DataValueField("Emp_num")
    .DataTextField("Emp_num")
    .BindTo((System.Collections.IEnumerable)ViewData["Employee"])
    .Events(e => e.Select("changes"))
)

javascript:

function changes(e)
{
    var Emp_num = this.dataItem(e.item).Emp_num;  // which gives the employee num
    getEmp(Emp_num, function (emp) {    //this function retrieve the details of employee for the particular employee number
        var Employee = emp;
        //here I need the code for update the values of Employee.description to description cell and Employee.address to address cell

    });
}

在没有看到您的代码的情况下,我想您有某种模板将您的dropdownlist定义为剑道网格列定义的一部分,对吧?您需要编写一个JavaScript函数来更新单元格,并将其添加到此下拉列表的onChange中。剑道医生可能会报道这一点。