Datasource "success" event?

1 Answer 5619 Views
Data Source
jc mag
Top achievements
Rank 1
jc mag asked on 24 Feb 2012, 03:15 PM
I'd like to display a message when the changes of a datasource are successfully saved in database, is there a 'success' event as the 'error' event?
Joshua
Top achievements
Rank 1
commented on 25 Feb 2012, 09:08 PM

I am having a problem with this as well. Can you please post if you find a solution?

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 27 Feb 2012, 09:04 AM
Hello,

DataSource change is the event that will be triggered if the operation completes successful.

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Joshua
Top achievements
Rank 1
commented on 27 Feb 2012, 04:13 PM

I am currently using the change event to track when data has changed, but it does not fire when an ajax operation fires. If it did, then i do not think it would fit my needs, because i need to know which operation was successful or failed. I have included a snippet to demonstrate what i am trying to do.

In the read and create operations, I would like to know if i have a success or failure during the ajax request. i used the same properties that i used in an $.ajax  call that works. for some reason, kendo is just not calling the callback.


var dataSource = new kendo.data.DataSource({
    transport: {
        read: { url: 'Services/RockService.svc/GetPeople',
            success: function (data) {
                alert(data);
            },
            error: function (xhr, error) {
                console.debug(xhr); console.debug(error);
            }
        },
        create: {
            url: "Services/RockService.svc/AddPerson",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                alert(data);
            },
            error: function (xhr, error) {
                console.debug(xhr); console.debug(error);
            }
        },
        update: {
            url: "Services/RockService.svc/UpdatePerson",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataType: "json"
        },
        destroy: {
            url: "Services/RockService.svc/DeletePerson",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataType: "json"
        },
        parameterMap: function (data, type) {
            var ret;
            switch (type) {
                case "read":
                    ret = data;
                    break;
                case "destroy":
                    ret = kendo.stringify(data.models[0]);
                    break;
                default:
                    {
                        var persons = new Array();
                        for (var i = 0; i < data.models.length; i++) {
                            persons[i] = data.models[i];
                        }
                        ret = kendo.stringify({ "Persons": persons });
                        break;
                    }
 
            }
            return ret;
        }
    },
    schema: {
        data: "d",
        model: Person
    },
    batch: true
});
Nikolay Rusev
Telerik team
commented on 29 Feb 2012, 02:49 PM

Hello Joshua,

DataSource change is wired to $.ajax success handler and error event of the DataSource is wired to $.ajax error handler.

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Joshua
Top achievements
Rank 1
commented on 29 Feb 2012, 03:03 PM

But how do you know what operation happend? If it calls the same success and error handlers for all 4 events? How could I let the user know that his Update succeeded vs his Read succeeded or his Delete?


Brendan provided a different solution that is working for me right now:
http://www.kendoui.com/forums/framework/data-source/how-to-get-the-result-true-or-false-of-an-operation-create-update-or-delete-from-the-server.aspx 
Nikolay Rusev
Telerik team
commented on 02 Mar 2012, 05:12 PM

Hello Joshua,

One way is to use complete handler of $.ajax or what's  implemented in the thread you mention.

All the best,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Joshua
Top achievements
Rank 1
commented on 02 Mar 2012, 05:34 PM

this is what i was looking for!
"One way is to use complete handler "
jc mag
Top achievements
Rank 1
commented on 06 Mar 2012, 02:50 PM

@Telerik: the datasource change event is triggered too many times. For example, in a grid, as soon as I click on the "Add new record" button, my change function is called... it should be called only when I click on "Save changes"...

Tomas
Top achievements
Rank 1
commented on 16 Mar 2012, 04:00 PM

Hi,
I did some tests and it seems to me, that "change" function can not be wired with ajax "success", because ajax "success" is triggered after data from url are loaded. But if I trigger read on data source, things in "change" are done immediately, not after url in read is loaded.
But when Nikolay says so... :)

Tomas
Tags
Data Source
Asked by
jc mag
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or