Javascript使用自定义按钮手动打开Kendo UI网格编辑器

Javascript Open Kendo UI Grid Editor Manually with Custom Button

本文关键字:Kendo UI 网格 编辑器 自定义 按钮 Javascript      更新时间:2023-09-26

有没有办法强制打开Kendo UI Grid使用的编辑器??我所说的强制打开是指我有一个网格,它可以添加、创建和删除行,但这是在我初始化Kendo网格时使用内置按钮完成的。

有没有一种方法或函数可以让我调用它来打开编辑器,这样我就可以把它附加到我定制的按钮上??

这是我创建网格的代码。(请注意,我删除了编辑,因为我不想单行编辑)

$("#userTable").kendoGrid({
        dataSource:{
            data: this.myCollection,
            schema: {
                model:{
                    fields:{
                        UserId: {type: "number"},
                        Firstname: {type: "string"},
                        Surname: {type: "string"},
                        Team: {type: "string"}
                    }
                }
            },
            pageSize: 5
        },
        change: this.OnChange,
        selectable: "multiple",
        pageable: true,
        editable: "popup",
        toolbar: ["create"],
        messages:{
            commands:{
                create: "Create"
            }
        },
        columns:[
            {field: "UserId", title: "User Id"},
            {field: "Firstname", title: "Firstname"},
            {field: "Surname", title: "Surname"},
            {field: "Team", title: "Team"}
    });

如有任何帮助或建议,我们将不胜感激。

谢谢,

使用Custom命令和editRow方法

...
command: { text: "Edit", click: customEdit }
...
function customEdit(e) {
   e.preventDefault();
   this.editRow($(e.currentTarget).closest("tr"));
}

演示

$("#btn").on("click", function() { 
var grid  = $("#userTable").data("kendoGrid");
grid.editRow(grid.select()); })

上面将允许您以编程方式编辑选定的网格行