Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI Grid Save on Cell Blur

I am trying to get my grid to save changes when you press enter or move off a cell (blur), and not have to use a save button in a grid toolbar.

I am having trouble getting it to work properly, my PHP/SQL works fine, so I am sure it is something wrong with the grid.

Here is my code:

$("#grid").kendoGrid({
dataSource: {
    transport: {
        read: WEBROOT+"admin/fetch-toppers",
        update: {
            url: WEBROOT+"admin/update-topper",
            type: "POST"
        }
    },
    error: function(e)
    {
        alert(e.responseText);
    },
    schema: {
        data: "data",
        model: {
            id: 'id',
            fields: {
                "id": {nullable: true},
                "Date": {editable: false},
                "name": {editable: false},
                "price": {editable: true}
            }
        }
    }
},
columns: [{field: "Date", width: 105}, {field: "name", title: "Topper"}, {field: "price", title: "Price", width: 125}],
height: 550,
filterable: true,
sortable: true,
pageable: true,
editable: true,
navigatable: true,
edit: function()
{
    //this.saveChanges()
}
});

I have tried many things and different events but it has no effect.

How can I get it to save cell values on blur?

like image 359
imperium2335 Avatar asked Dec 23 '12 15:12

imperium2335


2 Answers

In your DataSource add:

change: function (e) {
                        if (e.action == "itemchange") {
                            this.sync();
                        }
                    },

it should look like:

dataSource: {
transport: {
    read: WEBROOT+"admin/fetch-toppers",
    update: {
        url: WEBROOT+"admin/update-topper",
        type: "POST"
    }
},
error: function(e)
{
    alert(e.responseText);
},
change: function (e) {
                        if (e.action == "itemchange") {
                            this.sync();
                        }
},
schema: {
    data: "data",
    model: {
        id: 'id',
        fields: {
            "id": {nullable: true},
            "Date": {editable: false},
            "name": {editable: false},
            "price": {editable: true}
        }
    }
}

},

like image 75
Rodney Hickman Avatar answered Nov 17 '22 01:11

Rodney Hickman


You could try and use the change event of the dataSource to execute the sync method of the dataSource.

   $("#grid").kendoGrid({
dataSource: {
    transport: {
        read: WEBROOT+"admin/fetch-toppers",
        update: {
            url: WEBROOT+"admin/update-topper",
            type: "POST"
        }
    },
    change:function(){this.sync()},
    error: function(e)
    {
        alert(e.responseText);
    },
    schema: {
        data: "data",
        model: {
            id: 'id',
            fields: {
                "id": {nullable: true},
                "Date": {editable: false},
                "name": {editable: false},
                "price": {editable: true}
            }
        }
    }
},
columns: [{field: "Date", width: 105}, {field: "name", title: "Topper"}, {field: "price", title: "Price", width: 125}],
height: 550,
filterable: true,
sortable: true,
pageable: true,
editable: true,
navigatable: true,
edit: function()
{
    //this.saveChanges()
}
});
like image 25
Petur Subev Avatar answered Nov 17 '22 01:11

Petur Subev