Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI Grid, editable mode not working for local data

Tags:

kendo-ui

I am working with the Kendo UI Grid. This is my code:

<body>
<div id="myGrid"></div>

<script type="text/javascript">
$(function(){
    var rows =  [
    {name: "name001", id: "001", group: "G1"},
    {name: "name002", id: "002", group: "G1"},
    {name: "name003", id: "003", group: "G2"},
    {name: "name004", id: "004", group: "G2"},
    ];

    var myDataSource =
        new kendo.data.DataSource({
            data: rows,
            pageSize: 3,
        });

    myDataSource.read();
    $("#myGrid").kendoGrid({
        dataSource: myDataSource,
        columns: [
            {field:"name", title:"The Name"},
            {field:"id", title:"The Id"},
            {field:"group"},
            {command:["edit", "destroy"]}
            ],
        scrollable: false,
        pageable: true,
        sortable: true,
        groupable: true,
        filterable: true,
        editable: "inline"
    });

});
</Script>
</body>

But the edit is not working. Opening this grid in a browser gives me a grid that looks as expected with an Edit and a Delete button. I can delete rows with the Delete button. But clicking Edit changes the row into edit mode (with input fields in cells) but changing a value and pressing the Update button does nothing. The row remains in edit mode and the Update button doesn't switch back to "Edit" as it's supposed to. Can you tell me what's missing? Do I have to configure my datasource somehow?

like image 365
Manolo Avatar asked Jan 16 '23 02:01

Manolo


1 Answers

Yes you missed to configure your Grid's dataSource to know how to update the records. I assume that you want to edit the records only locally (on the client) - without sending them to the server. To actually close the Grid and apply the changes you can use the save event of the Grid and the refresh method.

Here is a jsbin with your case.

If you want to save these changes to the server I suggest you to start with the demos.

like image 152
Petur Subev Avatar answered Jan 21 '23 23:01

Petur Subev