javascript - 如何在弹出和内联模式下使用 Kendo UI Grid?

标签 javascript kendo-ui kendo-grid kendo-template

我正在使用带有自定义弹出模板的 Kendo Grid。

我想同时使用popupinline模式。添加新记录时,网格应使用弹出模式并打开我的自定义模板;编辑时应使用inline模式。

我提到了this DEMOthis blog article ,它展示了如何同时使用 popupinline 模式,但我无法使用自定义模板呈现弹出窗口。

谁能帮我解决这个问题吗?

谢谢。

这里是my DEMO :

HTML:

<h3>How to use Kendo-ui Grid use popup with custom template while adding and Inline while editing records</h3>
<div id="grid"></div>
<script id="popup-editor" type="text/x-kendo-template">
  <h3>Edit Person</h3>
  <p>
    <label>Name:<input name="name" /></label>
  </p>
  <p>
    <label>Age: <input data-role="numerictextbox" name="age" /></label>
  </p>
</script>

JS:

var ds = {
    data: createRandomData(20),
    pageSize: 4,
    schema: {
        model: {
            fields: {
                Id: { type: 'number' },
                FirstName: { type: 'string' },
                LastName: { type: 'string' },
                City: { type: 'string' }
            }
        }
    }
};

var grid = $("#grid").kendoGrid({
    dataSource: ds,
    toolbar: [ { text : "Add new record", name: "create", iconClass: "k-icon k-add"} ],
    // editable: "inline",
    editable: {
        mode: "popup",
        template: kendo.template($("#popup-editor").html())
    },
    pageable: true,
    columns: [
        { field: "FirstName", width: 100, title: "First Name" },
        { field: "LastName", width: 100, title: "Last Name" },
        { field: "City", width: 100 },
        { command: [ "edit" ]}
    ]
}).data("kendoGrid");

最佳答案

我已经编辑了你的并创建了这个新的 DEMO .

您可以使用剑道网格的setOptions方法动态地将编辑模式更改为与自定义模板一起弹出,如下所示:

$(".k-grid-popup", grid.element).on("click", function () {
    // change grid editable mode to popup and set the popup editing template
    grid.setOptions({
        editable: {
            mode: "popup",
            template: kendo.template($("#popup-editor").html())
        }
    });

    grid.addRow();
    grid.options.editable = "inline";
});

关于javascript - 如何在弹出和内联模式下使用 Kendo UI Grid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47073349/

相关文章:

javascript - Kendo UI 网格将 json 对象显示为 [object Object]

javascript - 如何将原型(prototype)函数添加到初始化函数中的事件监听器?

javascript - WMS 图层未在所有缩放级别上正确渲染

javascript - JavaScript 和 jQuery 中的单击源,人工还是自动?

javascript - 那里有什么好的 JavaScript 散列(代码/表)实现吗?

javascript - 如何在 GridView 中显示 NULL 值?

javascript - 剑道击倒 : Window does not close correctly

javascript - Kendo UI 分组过滤器

asp.net-mvc - 使用 Kendo 调度程序的问题

asp.net-mvc-4 - 使用仅包含带有 asp.mvc 包装器和数据源的网格的 KendoUI 自定义下载时出现 "Undefined is not a function"错误