I mistakenly clicked on reply-to-author and had a conversation with Tim over email. He has suggested some really good points in his email and I wanted to make sure that others could get benefited from that as well. So I am copying the conversation here.
Anirudh: I have to call $scope.$apply() each time after adding a row to the array I
initially set as 'data' to see the changes. Or otherwise if click on the
dropdown which shows search bar it refreshes the grid as well. So in short
for me it doesn't auto update. I am afraid I am doing something wrong. My
grid options is a fairly simple object with just the 'data' attribute set
and nothing else.
Tim:
are you setting the data within an ajax call or separate thread? that
is usually why. you need to use either the $http service or the
$timeout service if you don't want to run the setting of data within
an $apply(function(){$scope.data = newData;}); or calling
$scope.$digest after setting the data.
Anirudh:
Thanks for the reply. In my case the data is pushed by the server over a
web socket connection. My use case demands me to show live changes in
grid. Isn't there any function directly to change cells or add or delete
rows?
How does the update works? Is this documented somewhere? If I
update my grid contents too often and call $apply() after that will it
be a huge performance issue?
Tim:
$digest is really fast, you shouldn't have performance issues. What i
would suggest is keying your data model and then updating the data
directly in the $scope array instead of giving it new data
(overwriting) every time. that way the data can be updated repeatedly
without impacting performance.
on another note, I think what we want to support in the next version
is a primaryKey property on your datamodel. that way you can give the
grid data with a primary key field and we use that to compare and
update the data instead of doing it in a referential manner. This
would make it so the grid can see if the data already exists through
the primary key and operate accordingly.
_________________________________
Thanks again to Tim for the help.
On Sunday, 13 January 2013 12:29:08 UTC+5:30, Tim Sweet wrote:
It should be updating automatically as long as you are directly modifying the object you initially set to "data" in your grid options(push, pop, splice, reassignment).: