Our grid data comes as a part of a larger object returned by ajax call. Other properties of this object are used outside of the grid. Thus instead of dataSource.transport we use dataSource.data.
To let you better understand the following code snippets, I'll mention that the grid DataSource is defined inside AngularJS controller.
When the grid originally loads, it has no rows as the ticket.Comments array is empty.
Now, the Comments data comes in the ajax response returned by "Tickets" service:
However the grid does not show any records after this. I can step through the code and verify, that $scope.ticket gets an array of Comments before the read() is called.
I found a workaround by using a different data array and then updating elements of this array.
I had to use this extra loop to assign tmp elements because one liner "$scope.tmp = $scope.ticket.Comments;" does not work!
Is there a better way???
Thanks,
-Pavel
To let you better understand the following code snippets, I'll mention that the grid DataSource is defined inside AngularJS controller.
$scope.ticket = {
"Comments"
:[]};
$scope.commentsDS =
new
kendo.data.DataSource({
data:$scope.ticket.Comments,
schema:{model:{fields:{
txt: {type:
"string"
},
by: {type:
"string"
},
on: {type:
"string"
}
}}},
pageSize:10
});
Now, the Comments data comes in the ajax response returned by "Tickets" service:
if
($scope.objId > 0) {
Tickets.ticketPromise($scope.objId).then(
function
(response){
if
(response.data) {
$scope.ticket = response.data;
$scope.commentsDS.read();
}
});
}
I found a workaround by using a different data array and then updating elements of this array.
$scope.tmp = [{}];
$scope.ticket = {
"Comments"
:$scope.tmp};
$scope.comments =
new
kendo.data.DataSource({
data: $scope.tmp,
schema: { ... },
pageSize: 20
});
if
($scope.objId > 0) {
Tickets.ticketPromise($scope.objId).then(
function
(response){
if
(response.data) {
$scope.ticket = response.data;
for
(var
i = 0; i < $scope.ticket.Comments.length; i++){
$scope.tmp[i]=$scope.ticket.Comments[i];
}
$scope.comments.read();
}
});
}
Is there a better way???
Thanks,
-Pavel