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

Notify the dataSource that the request succeeded after a request

1 Answer 21 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Juan Jose
Top achievements
Rank 1
Juan Jose asked on 20 Aug 2015, 12:25 PM

Hi, i can´t get this to work when I don´t use batch=true.

This works for batch creation (i copied it from one of your examples), please notice the marked as bold and italic code:

var dataSource = new kendo.data.DataSource({
  transport: {
    read: function(options) {
      /* implementation omitted for brevity */
    },
    create: function(options) {
      $.ajax({
        dataType: "jsonp", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
        // send the created data items as the "models" service parameter encoded in JSON
        data: {
          models: kendo.stringify(options.data.models)
        },
        success: function(result) {
          // result is an array containing the recently created item
          options.success(result);
        },
        error: function(result) {
          // notify the data source that the request failed
          options.error(result);
        }
      });
    }
  },
  batch: true,
  schema: {
    model: { id: "ProductID" }
  }

 

 I guess the only difference should be:

 

var dataSource = new kendo.data.DataSource({
  transport: {
    read: function(options) {
      /* implementation omitted for brevity */
    },
    create: function(options) {
      $.ajax({
        dataType: "jsonp", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
        // send the created data items as the "models" service parameter encoded in JSON
        data: {
//Send a single object array, the webservice is expecting an array of objects, i first coded it so it would work mainly with batch=true  
models: kendo.stringify([options.data])
        },
        success: function(result) {
          //result is an array of objects. contains  the recently created item
          options.success(result);
        },
        error: function(result) {
          // notify the data source that the request failed
          options.error(result);
        }
      });
    }
  },
  batch: false,
  schema: {
    model: { id: "ProductID" }
  }

 

I tried sending and receiving an object instead an array of objects, but it didnt work either...

Thanks a lot for your help.

 

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 24 Aug 2015, 09:47 AM

Hello Juan Jose,

You approach seems valid in the context of our service - as it is implemented to receive an array of modified objects inside the model param. Please check the this dojo.

Depending on your own service implementation and if you want to send just one object (have the batch set to false) you could just assign the options.data to the $.ajax.data option. For example:

$.ajax({
   // rest of the configuration
   data: options.data // may required to be stringified
 });

Regards,
Rosen
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
Juan Jose
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or