将Kendo Grid所选项目传递到Kendo窗口中 [英] Passing Kendo Grid selected item into Kendo Window

查看:92
本文介绍了将Kendo Grid所选项目传递到Kendo窗口中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有可编辑记录的剑道网格:

I have got a Kendo Grid with editable records:

当用户单击编辑"按钮时,剑道窗口随即打开,其中包含用于编辑记录的表单.

When the user clicks the edit button, a Kendo Window opens with a form to edit the record.

我通过使用控制器方法填充Kendo窗口来实现这一目标,该方法通过Web服务获取所选记录的数据:<-这是我要避免的.相反,我想直接从表中取出数据并将其放入Kendo窗口内的输入字段,而无需任何其他处理或html调用.数据已经在表中了,我只是不知道如何将其发送到Kendo Window输入中.

I am achieving this by filling the Kendo Window from a controller method that fetches the data of the selected record via webservice: <- this is what I want to avoid. Instead, I want to take the data straight out from the table and put it into the input fields inside the Kendo Window, without any additional processing or html calls. The data is already on the table, I just don't know how to send it to the Kendo Window inputs.

以下是一些代码:

点击编辑"按钮后调用的javascript函数:

The javascript function called after clicking the edit button:

function openEdit() {
    var window = $("#editWindow").getKendoWindow();
    window.refresh({
        url: '@Url.Action("_EditForm", "Controller")'
    });
    window.center().open();
}

该视图包含部分视图调用:

The view contains a partial view call:

@Html.Partial("_EditWindow")

被调用的局部视图包含剑道窗口:

The called partial view contains the Kendo Window:

@(Html.Kendo().Window()
    .Name("editWindow")
    .Modal(true)
    .Events(e => e.Open("drawWindow").Close("refresh").Refresh("hideLoading"))
    .Iframe(true)
    .Visible(false)
    .Title("Edit Record")
)

如何将表中所选行中的数据传递到剑道窗口?

How can the data from the selected row of the table be passed to the Kendo Window?

编辑

EDIT

我知道如何从javascript中所选记录中获取值:

I know how to get the values from the selected record in javascript:

var grid = $("#grid").data("kendoGrid");
var selectedItem = grid.dataItem(grid.select());

我只是不知道如何将它们传递给Kendo Window输入.

I just don't know how to pass them into the Kendo Window inputs.

推荐答案

我为我的问题找到了解决方案.现在,我将选定的模型从视图发送到控制器.我使用出色的JSON.stringify来实现它.

I came to a solution for my problem. I now send the selected model from the view to the controller. I use the fantastic JSON.stringify to achieve it.

function onChange() {
    if (this.dataItem(this.select()) != null) {
        var rowModel = this.dataItem(this.select());
        // gets the model of the selected item in the grid

        $.ajax({
            url: 'sendGridRecord',
            type: "POST",
            data: JSON.stringify(rowModel),
            contentType: 'application/json'
        });
    }
}

这篇关于将Kendo Grid所选项目传递到Kendo窗口中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆