Beachdog
Beachdog

Reputation: 174

Kendo DataSource Update function Not Firing

I know this question has been asked with answers I have reviewed over and over. I still can not get this kendo dataSource update function to fire. It fires without the function(e) {}

 update: 
            {
                url: "/SettingsAdmin/UpdateGrid",
                dataType: "json",
                type: "POST",
                //data: {
                //    result: kendo.stringify(result.data)
                //},
            },

That works. What doesn't work is when I try implementing the update as a function

 update: function(e)
            {
                debugger
                alert("update")

                $.ajax({
                    url: "/SettingsAdmin/UpdateGrid",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                   
                    data: {                          
                        models: kendo.stringify(e.data.models)
                    },
                    success: function (result) {
                       
                        alert(e.success(result));
                    },
                    error: function (result) {        

                        alert(e.error(result))
                        e.error(result);
                    }
                });
            },

Here is the whole dataSource defined.

 return new kendo.data.DataSource({
        transport: {
            read: {
                url: url,
                contentType: 'application/json; charset=utf-8',
                type: "POST",
                dataType: "json"
            },
           
            update: 
            {
                url: "/SettingsAdmin/UpdateGrid",
                dataType: "json",
                type: "POST",
                //data: {
                //    result: kendo.stringify(result.data)
                //},
            },

            update: function(e)
            {
                debugger
                alert("update")

                $.ajax({
                    url: "/SettingsAdmin/UpdateGrid",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                   
                    data: {                          
                        models: kendo.stringify(e.data.models)
                    },
                    success: function (result) {
                       
                        alert(e.success(result));
                    },
                    error: function (result) {        

                        alert(e.error(result))
                        e.error(result);
                    }
                });
            },
            parameterMap: function (data, operation) {
                return JSON.stringify(data);
            }               
        },         
        schema:
        {               
            data: "result.data",
            total: "result.total",
            aggregates: "result.aggregates",
            groups: "result.groups",
            errors: "result.errors",
            model:
            {
                id: "name",
                //fields: {
                //    //id: { required: false, type: 'number', nullable: true },
                //    name: { editable: false, type: "string" },
                //    value: { editable: true, type: "string" }
                //}
            }
        },

        pageSize: 10,
        batch: false,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true,
    });

Upvotes: 0

Views: 412

Answers (1)

Beachdog
Beachdog

Reputation: 174

All transport actions (read, update, create, destroy) must be defined in the same way which I wasn't doing. I had defined my read action as

read: {
            url: url,
            contentType: 'application/json; charset=utf-8',
            type: "POST",
            dataType: "json"
        },

And then the update with a function

update: function(e)
        { }

Can't do that. I need to define my read: as a function

Upvotes: 1

Related Questions