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

Unable to add new record after deleting a record

1 Answer 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CS
Top achievements
Rank 2
CS asked on 02 Jun 2014, 08:30 AM
I have a custom create and a custom destroy method in use. The create simply return a custom object that mirrors the schema of the grid with preset values. The destroy does two things, first it deletes the entry via rest and then it removes the row.

When I reload I can create a new entry and everything. When I delete an entry and try to add a new one i get the following error:

Uncaught TypeError: Cannot read property 'call' of undefined kendo.all.js:7386
(anonymous function)                                                                    kendo.all.js:7386
b.extend.Deferred                                                                         jquery_1.9.1.min.js:4
Observable.extend._promise                                                      kendo.all.js:7382
Observable.extend._send                                                            kendo.all.js:7416
Observable.extend.sync                                                               kendo.all.js:7208
Observable.extend._change                                                        kendo.all.js:7609
b.extend.proxy.b.isFunction.i                                                       jquery_1.9.1.min.js:4
Class.extend.trigger                                                                     kendo.all.js:179
Observable.extend.splice                                                            kendo.all.js:5021
Observable.extend.insert                                                             kendo.all.js:7043
Widget.extend.addRow                                                               kendo.all.js:36077
(anonymous function)                                                                   kendo.all.js:36138
b.event.dispatch                                                                           jquery_1.9.1.min.js:4
b.event.add.v.handle

The create function is similar to the following
create: function (options) {
                var createNewRow = {
                    unit: { Name: ""},
                    number: {},
                    Id: { Name: ""},
                    Quantity: 1
                };
                options.success(createNewRow);
                // options.success(options);
            }

And the delete pretty much looks like this
function deleteProduct(e){
        var grid                  = $("#grid").data("kendoGrid"),
              currentRow            = $(e.currentTarget).closest("tr"),
              currentRowData        = this.dataItem(currentRow);

        grid.removeRow(currentRow[0]);

        grid.dataSource.read();
        grid.refresh();
    }

I had to remove some CRM dependant parts

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 04 Jun 2014, 08:46 AM
Hi Stefan,

I am not sure I understand what is the expected behavior. Basically, the create method should notify the DataSource what values were saved on the server and what ID was assigned to the item. A new, empty row is automatically created once the Add new record button is pressed. In case you wish to add a pre-populated items, then I would suggest checking this example. The destroy method does more or less the same - notifies the DataSource which item was deleted and was the operation successfully executed on the server. The row is automatically removed once the delete button is pressed or the removeRow method executed, so doing this and/or calling the DataSource's read method in the transport.destroy is not necessary. I would recommend using the following approach: 
  • Make a request to the server
  • Once the request's success event is triggered, get the response and pass it to the success method of the options argument of the CRUD method

For example: 
destroy: function (options) {
  $.ajax({
    url: "MyService/Destroy",
    data: ... //options.data
    success: function(result) {
      options.success(result);
    },
    error: function(result) {
      options.error(result);
    }
  });
}


Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
CS
Top achievements
Rank 2
Answers by
Alexander Popov
Telerik team
Share this question
or