I'm having issues when we try to refresh our kendo grid if we use a factory promise in our datasource. Here is a code sample of what we are trying to do:
In the html file:
<div data-ng-controller="ModalUserInbox as vm">
<div kendo-grid="vm.grid" options="vm.mainGridOptions" height="300"></div>
</div>
In the controller:
vm.mainGridOptions = {
dataSource: {
type: "json",
transport: {
read:
function (e) {
UserInboxFactory.getUserInbox().
then(function (data) {
e.success(data);
});
}
},
schema: {
model: {
fields: {
ColumnSelected: { type: "boolean" },
Extension: { type: "string", editable: false },
Subject: { type: "string", editable: false },
Client: { type: "string", editable: false },
CreatedOn: { type: "date", editable: false }
}
}
},
pageSize: 8,
serverPaging: false,
serverSorting: false,
autosync: true
},
In the factory UserInbox:
function UserInboxFactory($http, $q, RequestContext, Utility) {
var deferred = $q.defer();
var service = {
getUserInbox: getUserInbox
};
return service;
function getUserInbox() {
$http({
method: "GET", cache: false,
url: RequestContext.PathAPI + 'user/Message/UserInbox/'
}).success(function (data) {
deferred.resolve(data);
}).error(function (response) {
deferred.reject(response);
})
return deferred.promise;
}
}
This works great on first load but I added a refresh button which tries to refresh the data:
function refreshMessages() {
var grid = $("#grid").data("kendoGrid");
grid.dataSource.read();
grid.refresh();
}
I can see the call to get the data but the data never actually refreshes. What am I doing wrong? If I change the read to directly use the url from the factory everything works perfect.
In the html file:
<div data-ng-controller="ModalUserInbox as vm">
<div kendo-grid="vm.grid" options="vm.mainGridOptions" height="300"></div>
</div>
In the controller:
vm.mainGridOptions = {
dataSource: {
type: "json",
transport: {
read:
function (e) {
UserInboxFactory.getUserInbox().
then(function (data) {
e.success(data);
});
}
},
schema: {
model: {
fields: {
ColumnSelected: { type: "boolean" },
Extension: { type: "string", editable: false },
Subject: { type: "string", editable: false },
Client: { type: "string", editable: false },
CreatedOn: { type: "date", editable: false }
}
}
},
pageSize: 8,
serverPaging: false,
serverSorting: false,
autosync: true
},
In the factory UserInbox:
function UserInboxFactory($http, $q, RequestContext, Utility) {
var deferred = $q.defer();
var service = {
getUserInbox: getUserInbox
};
return service;
function getUserInbox() {
$http({
method: "GET", cache: false,
url: RequestContext.PathAPI + 'user/Message/UserInbox/'
}).success(function (data) {
deferred.resolve(data);
}).error(function (response) {
deferred.reject(response);
})
return deferred.promise;
}
}
This works great on first load but I added a refresh button which tries to refresh the data:
function refreshMessages() {
var grid = $("#grid").data("kendoGrid");
grid.dataSource.read();
grid.refresh();
}
I can see the call to get the data but the data never actually refreshes. What am I doing wrong? If I change the read to directly use the url from the factory everything works perfect.