Jsgrid: Use ajax to return data and itemCount in loadData function

Created on 18 Oct 2016  路  2Comments  路  Source: tabalinas/jsgrid

Is it possible to use ajax call to return data and itemCount in loadData function?

I tried this code below,it's working, but the thing is I don't want to use the async:false option. I don't what to wait for the return to interact to the page, is there any solution for this?

loadData: function (filter) {
         model = {
                page: 1,
                orderBy: "LastName",
                reverse: false,
                itemCount: 20,
                filters: null
            };            
          var _customer = $.ajax({
                type: 'GET',
                url: '@Url.Action("GetCustomers")',
                dataType: 'json',
                async: false,
                data: model
            });


            return {
                data: _customer.items,
                itemsCount: _customer.itemCount
            };
        },

on my controller, I return this structure

        return new {
          ItemCount = cModelView.Count(), // returns the items count
          Items = cModelView // returns the items
        };
help wanted

Most helpful comment

Yes, this is the basic scenario for jsgrid.
Here is a code snippet based on the demo referenced by @tonisostrat:

loadData: function() {
    var d = $.Deferred();

    $.ajax({ /* your config here */ }).done(function(response) {
        d.resolve({
            data: response.items,
            itemsCount: response.itemCount
       });
    });

    return d.promise();
}

All 2 comments

There's a whole demo page here concerning async data loading. See OData Service.

Yes, this is the basic scenario for jsgrid.
Here is a code snippet based on the demo referenced by @tonisostrat:

loadData: function() {
    var d = $.Deferred();

    $.ajax({ /* your config here */ }).done(function(response) {
        d.resolve({
            data: response.items,
            itemsCount: response.itemCount
       });
    });

    return d.promise();
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

julmarci picture julmarci  路  4Comments

aidankilleen picture aidankilleen  路  5Comments

eliasuardi picture eliasuardi  路  3Comments

danielson317 picture danielson317  路  3Comments

bradybray picture bradybray  路  3Comments