This is a migrated thread and some comments may be shown as answers.

Execute some code after successful grid item update on server.

2 Answers 881 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jose Mejia
Top achievements
Rank 1
Jose Mejia asked on 27 Aug 2014, 04:45 PM
Hi.

I'm using grid and I can't find a normal solution to execute some code after successful item update on the server.
var ds = new kendo.data.DataSource({
 
  transport: {
        read: {
            url: 'stations',
            dataType: 'json'
               },
         update: {
            url: 'stations',
            dataType: 'json',
             type: 'PUT'
            },
         destroy: {
           url: 'stations',
           dataType: 'json',
             type: 'DELETE'
        },
        create: {
          url: 'stations',
           dataType: 'json',
            type: 'POST'
         },
     parameterMap: function (data, operation)
       {
          if (operation !== "read" && data)
          {
              return JSON.stringify(data);
           }
        }
   },
   batch: false,
 
    schema: {
         model: {
             id: "Id",
                 fields: {//some fields... }
 
                    }
                }
            });

The most obvious solution to me was to use update function with ajax (as in documentation samples). But it doesn't work. There are some work arounds on SO I found, but they seems not  good to me. Handling grid save event is not useful because it is raised before server update. Also I tried to use requestEnd event on ds, but it is not obviouse how to differentiate success and error request. And the more important thing is that I have no access to updated item in the requestEnd handler.

So the question: is there some mechanisms to execute some js code with updated item after successful server update within grid?

If it is important, I use angular-kendo.

Thanks in advance.


2 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 29 Aug 2014, 11:18 AM
Hello Jose,

If there is error, the error event of the dataSource will be triggered. Inside the requestEnd event you have access to the response so if you have returned the updated item from the server then you should have it available.

http://docs.telerik.com/kendo-ui/api/framework/datasource#events-requestEnd

Kind Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jose Mejia
Top achievements
Rank 1
answered on 29 Aug 2014, 04:38 PM
Thank you!

It was obvious solution, but in my API I returned object id after it was updated instead of object. It is good idea to return object.

Thanks again.
Tags
Grid
Asked by
Jose Mejia
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Jose Mejia
Top achievements
Rank 1
Share this question
or