Daniel
Daniel

Reputation: 1198

Kendo DataSource Single-Row Read

I have a mobile app that receives a push notification, when it does, I know there is a row that that needs to be updated. I have tried two methods for retrieving just that one:

var row = data_source.get(<id>);
row.dirty = true;
data_source.sync();

This tries to fire an UPDATE, which I could shoe-horn into doing what I want, but it's conceptually wrong.

The other option that I have tried:

data_source.read( { id : <id> } );

Which fires off a READ request, with the ID in options.data. When I try to hook this up, kendo complains about not getting an array back, and when I make the response into an array, it doesn't seem to work either.

How am I supposed to do this? GET it outside the context of the DataSource, and set the relevant parts, and then set the dirty bit to false?

Upvotes: 3

Views: 1515

Answers (1)

Vojtiik
Vojtiik

Reputation: 2560

Kendo doesn't do single row read out of the box. If its not feasible to do full read(), you have to do what you proposed. Try following :

1) make your server side read method to accept requests with or without id, without to read all items, with to read your one row.

2) use parameter map together with isPushNotificaton flag to control the read request params

parameterMap: function(data, type) {
  if (type == "read") {
    if (isPushNotificaton)
          return { id : yourId };
    else
          return { id : 0}; // get all 
    }
  }

3) use requestEnd to decide how to deal with read result

     requestEnd: function(e) {
            var type = e.type;
            if (e.type == 'read') {

               // examine the response(by count/add additional flags into response object)
               var isFullReadResponse = ...;

               if (!isFullReadResponse) {
                  // DIY
                  e.preventDefault();
                  UpdateSingleRow(response, datasource.data());
               } 
            } 
     }

4) Implement UpdateSingleRow method as you proposed - .."and set the relevant parts, and then set the dirty bit to false", (Refresh a single Kendo grid row)

Upvotes: 3

Related Questions