从Kendo MVC Grid的PopUp编辑器窗口处理事件 [英] Handling events from a Kendo MVC Grid's PopUp editor window

查看:97
本文介绍了从Kendo MVC Grid的PopUp编辑器窗口处理事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Html.Kendo().Grid助手创建的Kendo MVC网格.当PopUp编辑器窗口打开时,我想捕获事件并运行一些javascript.当我使用.Events配置普通剑道窗口时,事件会正确触发并且我的函数会运行.但是,当我在网格的.Editable.Window上编写.Events属性时,事件不会触发.

I have a Kendo MVC grid that I am creating with the Html.Kendo().Grid helper. When the PopUp editor window opens, I want to catch the event and run a bit of javascript. When I configure a normal kendo window with .Events, the events fire properly and my function runs. However, when I code the .Events property on the .Editable.Window of the grid, the events do not fire.

@(Html.Kendo().Grid<FooRecord>()
.Name("cFooGrid")
        .Columns(c =>
        {
            c.Bound(f => f.Foo);
            c.Bound(f => f.Bar);
            c.Bound(f => f.Bas);
            c.Command(a => a.Edit());
        })
        .Editable(e => e
            .Mode(GridEditMode.PopUp)
            .Window(w => w.Events(v => v.Open("OnEditStart").Activate(@<text>function () {console.log("EditWindow.Activate")}</text>)))
        )
        .ToolBar(t =>
        {
            t.Create();
        })
        .DataSource(ds => ds
            .Ajax()
                .Create(r => r.Action("UpdateIndex", "Home"))
                .Read(r => r.Action("IndexList", "Home"))
                .Update(u => u.Action("UpdateIndex", "Home"))
            .Model( m => {
                m.Id(f => f.Foo);
            })
        )

)

当我在Chrome的开发人员工具中查看生成的代码时,生成的窗口没有激活或打开功能:

When I review the generated code in Chrome's developer tools, the window is generated without the Activate or Open features:

    jQuery(function(){jQuery("#cFooGrid").kendoGrid({"columns":[{"title":"Foo Key","field":"Foo","encoded":true,"editor":null},{"title":"Bar Field","field":"Bar","encoded":true,"editor":null},{"title":"Bas Value","field":"Bas","encoded":true,"editor":null},{"command":[{"name":"edit","buttonType":"ImageAndText","text":"Edit"}]}],"scrollable":false,"editable":{"confirmation":"Are you sure you want to delete this record?","confirmDelete":"Delete","cancelDelete":"Cancel","mode":"popup","template":"\u003cdiv class=\"editor-label\"\u003e\u003clabel for=\"Foo\"\u003eFoo Key\u003c/label\u003e\u003c/div\u003e\u003cdiv class=\"editor-field\"\u003e\u003cinput class=\"k-textbox\" id=\"Foo\" name=\"Foo\" /\u003e\u003cspan class=\"field-validation-valid\" data-valmsg-for=\"Foo\" data-valmsg-replace=\"true\"\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv class=\"editor-label\"\u003e\u003clabel for=\"Bar\"\u003eBar Field\u003c/label\u003e\u003c/div\u003e\u003cdiv class=\"editor-field\"\u003e\u003cinput class=\"k-textbox\" data-val=\"true\" data-val-maxlength=\"The field Bar Field must be a string or array type with a maximum length of \u0026\\#39;20\u0026\\#39;.\" data-val-maxlength-max=\"20\" id=\"Bar\" name=\"Bar\" /\u003e\u003cspan class=\"field-validation-valid\" data-valmsg-for=\"Bar\" data-valmsg-replace=\"true\"\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv class=\"editor-label\"\u003e\u003clabel for=\"Bas\"\u003eBas Value\u003c/label\u003e\u003c/div\u003e\u003cdiv class=\"editor-field\"\u003e\u003cinput class=\"k-textbox\" data-val=\"true\" data-val-required=\"The Bas Value field is required.\" id=\"Bas\" name=\"Bas\" /\u003e\u003cspan class=\"field-validation-valid\" data-valmsg-for=\"Bas\" data-valmsg-replace=\"true\"\u003e\u003c/span\u003e\u003c/div\u003e","window":{"title":"Edit","modal":true,"draggable":true,"resizable":false},"create":true,"update":true,"destroy":true},"toolbar":{"command":[{"name":null,"buttonType":"ImageAndText","text":"Add new record"}]},"dataSource":{"type":(function(){if(kendo.data.transports['aspnetmvc-ajax']){return 'aspnetmvc-ajax';} else{throw new Error('The kendo.aspnetmvc.min.js script is not included.');}})(),"transport":{"read":{"url":"/Home/IndexList"},"prefix":"","update":{"url":"/Home/UpdateIndex"},"create":{"url":"/Home/UpdateIndex"}},"serverPaging":true,"serverSorting":true,"serverFiltering":true,"serverGrouping":true,"serverAggregates":true,"filter":[],"schema":{"data":"Data","total":"Total","errors":"Errors","model":{"id":"Foo","fields":{"Foo":{"type":"string"},"Bar":{"type":"string"},"Bas":{"type":"string"}}}}}});});

或者,更具体地说:

"window":{"title":"Edit","modal":true,"draggable":true,"resizable":false}

我希望该窗口将使用Activate:和Open:参数生成,但不会显示.有人可以给我指点一下这是否不受支持或我做错了什么吗?

I would expect that the window would be generated with Activate: and Open: parameters, but they don't show up. Can anyone give me a pointer as to whether this just isn't supported or I am doing something wrong?

因此,为了捕获上述事件,有两个步骤: 将此添加到网格定义(删除Window .Events)

So in order to capture the events as above, there are two steps: Add this to the grid definition (remove the Window .Events)

        .Events(e => e.Edit("OnEditStart"))

然后在页面上添加一个像这样的javascript函数.

Then add a javascript function like this to the page.

function OnEditStart(pEvent) {
var editWindow = pEvent.container.data('kendoWindow');
editWindow.bind('activate', function () {
    console.log('Edit start event fired');
});

}

注意:似乎没有任何方法可以捕获打开事件,因为此事件是在网格上的编辑事件之前在窗口上触发的.

NOTE: There does not appear to be any way to capture the open event since this event is fired on the window before the edit event on the grid.

推荐答案

剑道网格弹出窗口的事件"未被兑现/序列化(至少不是我上次在2014年进行的测试),因此您应该使用网格的Edit事件以控制弹出窗口"窗口事件

The "events" of the kendo grid popup are not honoured/serialized (at least not the last time I tested this back in 2014) and so you should use the grid's Edit event to control the "Pop Up" window events

因此,在您的网格中添加以下内容:

So within your grid add this:

.Events(event => event.Edit("onEdit"))
.//other grid settings here. 

然后添加一个像这样的javascript函数:

Then add a javascript function like this:

function onEdit(e) {

    //get window object
    var kendoWindow = e.container.data("kendoWindow");

        kendoWindow.setOptions({
            title: "I have a custom Title"

            //do stuff in here 

        });


}

然后,您可以通过javascript将所需的功能应用于窗口.

Then you can apply what ever functions you want to the window via javascript.

我执行类似的操作来调整弹出编辑器的大小,因此无论显示/设备如何,它都会占用屏幕大小的80%.

I do something similar to this to resize the pop up editor so it takes up 80% of the screen size regardless of the display/device.

如果您有更具体的信息,我将相应地更新我的答案.

If you have something more specific you are after then I will update my answer accordingly.

编辑:如果您愿意,可以从Telerik自己的论坛中参阅此帖子,这是我在2014年中首次遇到此问题时所使用的.

edit: If you want you can refer to this post from Telerik's own forums which is what I used when I first encountered this issue back in mid 2014.

Kendo弹出编辑器未触发应用事件

这篇关于从Kendo MVC Grid的PopUp编辑器窗口处理事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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