Kendo Grid calls 'create' operation instead of 'update' after adding new record

Viewed 5407

I've setup a basic Kendo Grid and I'm using the DataSourceResult class from the PHP Wrapper library on the sever side.

I've come across a strange issue... if I create a new record and then edit it (without refreshing the page), the create operation is called again, rather than the update operation.

If the page is refreshed after adding the new record, the update operation is called correctly after making changes to the record.

I can confirm that the DataSourceResult class is returning the correct data after the create operation, including the id of the new record.

Any ideas why this is happening (and how to stop it)? Thanks

Update: Here's the datasource code. The query string in the url is just to easily distinguish the requests in Chrome's console. The additional data passed with each request is used by ajax.php to distinguish the different actions requested.

data = new kendo.data.DataSource({
    transport: {
        create:  {
            url: '/ajax.php?r=gridCreate',
            dataType: 'json',
            type: 'post',
            data: { request: 'grid', type: 'create' }
        },
        read:  {
            url: '/ajax.php?request=gridRead',
            dataType: 'json',
            type: 'post',
            data: { request: 'grid', type: 'read' }
        },
        update: {
            url: '/ajax.php?r=gridUpdate',
            dataType: 'json',
            type: 'post',
            data: { request: 'grid', type: 'update' }
        },
        destroy: {
            url: '/ajax.php?r=gridDestroy',
            dataType: 'json',
            type: 'post',
            data: { request: 'grid', type: 'destroy' }
        },
        parameterMap: function(data, operation) {
            if (operation != "read"){
              data.expires = moment(data.expires).format('YYYY-MM-DD HH:mm');
            }
            return data;
        }
    },
    schema: {
        data: 'data',
        total: 'total',
        model: {
            id: 'id',
            fields: {
                id: { editable: false, nullable: true },
                code: { type: 'string' },
                expires: { type: 'date' },
                enabled: { type: 'boolean', defaultValue: true }
            }
        }
    },
    pageSize: 30,
    serverPaging: true,
    serverSorting: true,
    serverFiltering: true 
});
4 Answers

Pass the auto-incremented id of the table when you call the get_data() method to display data into kendo grid, so that when you click on the delete button then Deledata() will call definitely.

enter image description here

Another variation, in my case, I had specified a defaultValue on my key field:

        schema: $.extend(true, {}, kendo.data.transports["aspnetmvc-ajax"], {
            data: "Data",
            total: "Total",
            errors: "Errors",
            model: kendo.data.Model.define({
                id: "AchScheduleID",
                fields: {
                    AchScheduleID: { type: "number", editable: true, defaultValue: 2 },
                    LineOfBusinessID: { type: "number", editable: true },

Not sure what I was thinking but it caused the same symptom.

Related