Andrei M
Andrei M

Reputation: 3439

Kendoui grid destroy method doesn't refresh grid

I have a kendoui grid (no server-side wrappers). It has several columns displayed and "destroy" (delete) button. Everything works just fine. But it two issues:

  1. When I click "delete" button, then a request to a server is sent (a record is sucessfully deleted on the server). I return a new list of records from the server (after processing a "delete" request). But this new list of records is ignored and not used on the client. And I have to use "requestEnd" grid event to refresh the grid. Hence two HTTP requests are made to the server: "delete a record", "load new list of records". Is it possible to delete a record and return a new list of records from the server usign one single HTTP request?

  2. Also when I click "delete" button the appropriate grid row is immediatelly deleted (user-interface only), then a HTTP request is sent to the server. Is it possible to delete the record from the grid (UI) only after HTTP request is processed?

P.S. Previously when I used Telerik MVC Extensions (before kendoui) it worked fine.

Upvotes: 0

Views: 2208

Answers (1)

Vojtiik
Vojtiik

Reputation: 2560

  1. Destroy call is executed after the item is removed from the datasource.data() collection, therefore there is no need to return list. If your delete somehow effect other items in the list, call datasource.read form destroy.complete (but yes these are two calls). At the other hand, nothing is stopping you from returning complex json object as a result of delete, where one of the properties would be your list, unwrapping it on destroy.complete and assigning property with the collection to the datasource, doable. Although consider paging, sorting and other features you will have to deal with if you decide to take it this way.

  2. It is, you can implement custom command and implement the delete process as you wish, using the api.

Examples :

A) pagination and filters down to the server, assuming you enabled server side paging.

 parameterMap: function (o, operation) {
                            var output = null;
                            switch (operation) {
                                case "create":
                                    break;
                                case "read":
                                    output = '{ filter: ' + JSON.stringify(o) + '}';
                                    break;
                           }
                          return output;
                        }
                    },

B) Creating complex json is server side platform specific, in theory you wrap the actual json you are about to return to the client and wrap it into other json, add extra properties and then return it. You can then read it in a following way:

transport: {
         destroy: {
             complete: function (jqXhr, textStatus) {
                       var result = jQuery.parseJSON(jqXhr.responseText);
                       var yourdata = result.yourdata   
                       // pass your data to datasource  
                      }
               }
           }

Upvotes: 1

Related Questions