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
};
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();
}
Most helpful comment
Yes, this is the basic scenario for jsgrid.
Here is a code snippet based on the demo referenced by @tonisostrat: