Scott
Scott

Reputation: 2760

Kendo Grid doesn't display data if I use a function call for the data

If I use the second read below that is commented out, the grid displays my data. If I use the first, I can see my data being returned in Fiddler, but the grid doesn't display it.

var $nisGridDataSource = new kendo.data.DataSource({
    transport: {
        read: function () {
            DataService.newIssuesStatistics();
        }
        //read: {
            //url: "/api/PoolApi/NewIssuesSecurities"
        //}
    }

...

This is the DataService.newIssuesStatistics method that is called sucessfully:

    newIssuesSecurities = function () {

    return $.ajax({
        url: "/api/PoolApi/NewIssuesSecurities"
    });

Can anyone suggest why this is so?

Upvotes: 0

Views: 81

Answers (2)

Scott
Scott

Reputation: 2760

I ended up with this. Thanks Brett. Whom I now see answered with a full code example. So thanks again, Brett!

var $nisGridDataSource = new kendo.data.DataSource({
    transport: {
        read: function (options) {
            DataService.newIssuesStatistics()
                .done(function (result) {
                    // notify the data source that the request succeeded
                    options.success(result);
                })
                .fail(function (result) {
                    // notify the data source that the request failed
                    options.error(result);
                });
        }
    }

Upvotes: 0

Brett
Brett

Reputation: 4269

You have to tell the Kendo UI DataSource that it's received data. How is your function Dataservice.newIssuesStatistics() implemented? Does it return a promise? Let's say for illustrative purposes that it does, then this is how you would do it:

var dataSource = new kendo.data.DataSource({
  transport: {
    read: function(options) {
      Dataservice.newIssuesStatistics().done(function(stats) {
        options.success(stats);
      });
    }
  }
});

Upvotes: 1

Related Questions