在使用MVC版本的Kendo UI Grid时如何获得客户端编辑器?

时间:2015-05-13 09:30:10

标签: kendo-ui kendo-asp.net-mvc

嗯,我真的被困在这里了。 This example by Telerik显示了在编辑时将字段更改为您需要的内容。确切地说,

columns: [
           { field: "Category", title: "Category", width: "180px", editor: categoryDropDownEditor, template: "#=Category.CategoryName#" },
         ],

... where" categoryDropDownEditor"是一个客户端功能,可以解决这个问题。

在MVC版本中,似乎没有任何类型。在那儿?我一直相信它应该。每次我需要装饰输入字段时,我都不需要从服务器遍历部分HTML。这似乎是" EditorTemplate"是MVC唯一可用的。

1 个答案:

答案 0 :(得分:1)

行。万一有人会遇到同样的问题。我结束了这个"太优雅"解决方案:

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

网格初始化例程(服务器端)中的这一行调用命名的动态方法(客户端):



function editing(e) {
        var input = e.container.find("input[name=Regex]");
        var textbox = $(document.createElement('textarea')).attr({
            id: input.id,
        }).width(input.width()).height(input.height()).val(input.val());
        input.hide();
        textbox.insertAfter(input);
        textbox.focus(function () {
            /*to make this flexible, I'm storing the current width & height in an attribute*/
            $(this).attr('data-defaultwidth', $(this).width());
            $(this).attr('data-defaultheight', $(this).height());
            $(this).animate({
                width: 400
            }, 'slow');
            $(this).animate({
                height: 300
            }, 'slow');
        }).blur(function () {
            /* lookup the original width */
            var w = $(this).attr('data-defaultwidth');
            var h = $(this).attr('data-defaultheight');
            $(this).animate({
                width: w
            }, 'slow');
            $(this).animate({
                height: h
            }, 'slow');
            input.val(textbox.val());
            input.trigger('change');
        });
    }




结束tada,虽然它是一个纯粹的黑客。

相关问题