javascriptkendo-uikendo-gridkendo-template

How to use Kendo UI Grid with both popup and inline modes?


I am using Kendo Grid with custom popup template.

I want to use the popup and inline modes together. When adding new records, the grid should use popup mode and open my custom template; when editing, it should use inline mode.

I have referred to this DEMO in this blog article, which shows how to use the popup and inline modes together, but I am not able to render the popup with my custom template.

Can anyone help me in resolving this issue?

Thanks.

Here is 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");

Solution

  • I have edited your and created this new DEMO.

    You can use Kendo grid's setOptions method to dynamically change the edit mode to popup along with your custom template like below:

    $(".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";
    });