简体   繁体   English

如何在剑道网格上向文本框显示所选行

[英]how to display the selected row on kendo grid to the textbox

I am new to Kendo grids. 我是剑道网格的新手。 I have a kendo grid that displays the Id,name,Email Id. 我有一个显示ID,名称,电子邮件ID的Kendo网格。 So if a select a row that complete row should be displayed in the texboxes related to the fields(Id,name,Email). 因此,如果选择完整的行,则应在与字段(Id,名称,电子邮件)相关的texbox中显示该行。

You can make a function to fill your form and an easy way to do it is to use the input ids as the same as the data properties. 您可以创建一个函数来填写表单,一种简单的方法是使用输入id与数据属性相同。 Example below: 下面的例子:

change: function(e) {
    var dataItem = this.dataItem(this.select());
    fillForm(dataItem);
}

And the fillForm function: fillForm函数:

var fillForm = function(dataItem) {
    var columns = $("#grid").data("kendoGrid").options.columns;
    var form = $("form");

    for (var i = 0; i < columns.length; i++) {
        var field = columns[i].field;
        form.find("#" + field).val(dataItem[field]);
    }
}

This will run a reflection logic to fill automatically your form, being you form like: 这将运行一个反射逻辑来自动填写您的表单,如下所示:

<input type="text" id="Id" />
<input type="text" id="Name" />
<input type="text" id="LastName" />

And your data like: 您的数据如下:

{
    Id: 1,
    Name: "John",
    LastName: "Doe"
}

Demo . 演示 I hope it helps. 希望对您有所帮助。

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

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