User.Anonymous
User.Anonymous

Reputation: 1726

Update not working with Kendo datasource

I have an issue with Kendo Datasource, the update is never fired while the change is well fired with modified Object.

The datasource is very simple :

    collection: new kendo.data.DataSource({
        autoSync: false,
        batch: true,
        transport: {
            read: {
                url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignettes_Read",
                dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
            },
            update: {
                url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignette_Update",
                dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
            },
            schema: {
                model: {
                    id: "Id"
                }
            }
        },
        change: function (e) {

            console.log(this);
            console.log(e);

            //Not working too
            //if (e.action == "itemchange") {
            //    debugger;
            //    vignettesViewModel.collection.pushUpdate(e.items[0]);
            //}

            $('.vignette').detach();
            for (var i = 0; i < vignettesViewModel.collection.data().length; i++) { 
                vignettesViewModel.createVignetteUI(vignettesViewModel.collection.data()[i]);                    
            }

            vignettesViewModel.init()
        }
    })

For the test, autosync is set at false and batch is set at true.

Later in code, I update the datasource and I fired explicity the datasource by sync() methods

    //Some logic up
        var data_hospit = vignettesViewModel.getByUid($(ui.element).data('uid'));
    //Another logic
        data_hospit.set('date_debut', cellDepart.data('date'));
        data_hospit.set('date_fin', cellArrivee.data('date'));
        data_hospit.set('PrenomNomEtDateDeNaissance', 'toto');

        vignettesViewModel.collection.sync();

update is not fired but I see well that object changed go through change function. So why update is never fired ? I have well define model with id : 'Id' and if I change update string to a dummy function alert(), this is not working too. I ve tried to "force" update with pushUpdate but I have got an error "undefined function"

Thanks for your help

Upvotes: 2

Views: 1090

Answers (1)

OnaBai
OnaBai

Reputation: 40887

schema is not part of transport, you wrote:

   transport: {
        read: {
            url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignettes_Read",
            dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
        },
        update: {
            url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignette_Update",
            dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
        },
        schema: {
            model: {
                id: "Id"
            }
        }
    },

and it should be:

   transport: {
        read: {
            url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignettes_Read",
            dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
        },
        update: {
            url: "http://localhost:81/GPL/Main/Sources/GPL.Web.MVC/Vignette/Vignette_Update",
            dataType: "json" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
        }
    },
    schema: {
        model: {
            id: "Id"
        }
    }

Upvotes: 2

Related Questions