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

datasource - transport:read from local array not from URL

7 Answers 1236 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 24 Apr 2012, 04:44 PM
I want to read from an array and perform CRUD operations on this array but am struggling to find examples of this as all the transport:read examples read the data from a URL instead of an array.

The below works but does not need the CRUD operations

function listTicketsInit() {     
     
    var ticketdata = <?=json_encode($tickets)?>;
      
     var ticketDataSource = new kendo.data.DataSource({
         data: ticketdata,
         dataType: "json",
         schema: {
           model: {
               id: "ThreadID",
               fields: {
                   DateCreated: "DateCreated",
                   ThreadID: "ThreadID",
                   Subject: "Subject",
                   Closed: "Closed"                       
                  }
              }
          }
      });
 
     $("#support_list").kendoMobileListView({
         dataSource: ticketDataSource,
         //pullToRefresh: true,
         appendOnRefresh: true,
         style: "inset",
         template: $("#support_list_template").text()
     });
      
}

The below does not work with and I get "g is undefined" error.  Im not sure of the syntax and how to  get it to read from the array.

var messagedata = <?=json_encode($messages)?>;
 
var messageDataSource = new kendo.data.DataSource({
     
  data: messagedata, 
  
  transport: {
      update: {
          url: "/messages/markasread/<?=$message->message->id?>/0",
          type: "GET"
      },
      destroy: {
          url: "/messages/delete/<?=$message->message->id?>",
          type: "GET"
      }
  },           
     
  schema: {
    model: {
        id: "id",
        fields: {
            created: "created",
            message: "message",
            customer_name: "customer_name",      
            isnew: "isnew",      
           }
       }
   }
 });
 
$("#message_list").kendoMobileListView({
    dataSource: messageDataSource,
    //pullToRefresh: true,
    appendOnRefresh: true,
    style: "inset",
    template: $("#message_list_template").text()
});


Can anyone advise?

7 Answers, 1 is accepted

Sort by
0
autoabacus
Top achievements
Rank 1
answered on 09 Jul 2012, 04:05 AM
Unfortunately I don't have a solution, just the same problem with a grid.

I want to set my grid data from an array.  (The array is obtained via a url but with our own security processing thus I can't use the simple Kendo transport read.)

I also get the "g is undefined" error when attempting to use Update without read.

I actually would like all of the CRUD operations in transport to allow a function rather than a url. A plain url without  ability to package the Ajax call in the way I want (mainly for session security though also other things) does not suit our needs.

Is there any way to use a function call instead of a url?



0
autoabacus
Top achievements
Rank 1
answered on 12 Jul 2012, 06:20 AM
Via a support ticket I found out that there is indeed a way to use a function.

The object for read (and other transport options) can be a function e.g.:

dataSource: {
  transport: {
    read: function(options){
        options.success(data); // where data is the local data array
    },
...

and options is passed as
      data  Object {aggregate undefined, filter undefined, group [], sort undefined}
      error function()
      success function() 
      
The new Q2 doc released 11 July 12 is indeed better, but it still does not cover this capability.
0
Keith
Top achievements
Rank 1
answered on 13 Jul 2012, 07:18 PM
Thanks very much for sharing this with us autoabacus.

It worked great as far as allowing you to initialize the datasource from a local object but now when I try to run the sync() function I get an error: g[e].call is not a function

I'm using version 2012.2.710 from the CDN.

I really do like Kendo UI a lot but I'm finding trying to do anything but the basics is difficult and once it seems one thing is solved another pops up :)
0
autoabacus
Top achievements
Rank 1
answered on 14 Jul 2012, 12:26 AM
Yes, I also obtained that error when I had a mixture of functions and urls e.g. a function for read: and a url for update:

I switched to the full source so that the JS errors would make more sense, and in this case obtain:
transport[type].call is not a function in kendo.web.js (line 6185)
where type = 'update' and update was the one I had as a url.

When I changed to using functions for both read and update this particular error went away.

I still could not do all of what I wanted however, and have encountered another error when keyboard navigation of the grid is enabled.

Further I don't yet see how I can constrain keyboard nav to the editable cells for Enter as well as Tab, as I do for my forms via a keydown handler.

Yesterday I  submitted another ticket with 5 issues in it, but am still waiting for a response, given the awful 72 hour period of trial ticket responses. Though I notice that even if one buys, the guaranteed response times are only 24 or 48 hours according to package, which are not good enough.

So, like you, though I do like Kendo UI, I am finding it difficult to move beyond the basics, and have great reservations about support. If i were to go with Kendo for our app which is large and complex, I would have to become familiar with the source code so that I could support myself. At least it is possible to do that, but at a big cost in time and effort.
0
Keith
Top achievements
Rank 1
answered on 16 Jul 2012, 05:05 PM
Hopefully you hear something soon in regards to your ticket. If not I'll submit a ticket as well to hopefully add urgency.
0
autoabacus
Top achievements
Rank 1
answered on 18 Jul 2012, 12:20 AM
I have received a response to my ticket, which acknowledges the bug I mentioned, which applies when autoSync:true and navigatable:true are both used, so a fix for that issue is in the works.....  (As an aside, navigable would have been a nicer name for the attribute than navigatable.)

As to my other requests to do with constraining keyboard nav to the editable cells, and making Enter work like Tab, Kendo does not provide an 'out of the box' way for these things to be done, so I would have to program them myself.

I am considering what to do.
0
Keith
Top achievements
Rank 1
answered on 19 Jul 2012, 03:25 AM
Well hopefully the fix is in place soon and you find ways around your other issues.

In the meantime I want to have my solution working end to end so I put in place a hack to do this until that happens. Although it's not very clean and you may not be interested I wanted to include it anyway just in case:

Since update needs to be a function I use the following:

update: function(options) {
  $.ajax({
    type: "POST",
    url: "<my_url>",
    data: options.data,
    dataType: "json",
    success: function(data, textStatus, jqXHR) {
        options.success(data, textStatus, jqXHR);
    },
    error: function(jqXHR, textStatus, errorThrown) {
      options.error(data, textStatus, jqXHR);
    },
  });
}

The one good thing about this is when the fix is in place all that needs to happen is to remove everything from above except url (and type if you are using post).
Tags
Data Source
Asked by
Lee
Top achievements
Rank 1
Answers by
autoabacus
Top achievements
Rank 1
Keith
Top achievements
Rank 1
Share this question
or