ng-grid doesn't update data
http://stackoverflow.com/questions/24791142/ng-grid-doesnt-update-data
I pasted your code into a plunker and don't see anything wrong with it: http://plnkr.co/edit/DouHrm?p=preview
If you can paste the data that your server is returning as well as your HTML that would be helpful. Otherwise I'm not seeing anything wrong.
Note that I did remove your manual call to $scope.$apply() because it was throwing an exception. You're already in $digest in an $http promise handler.
Also you need to bind to filterOptions.filterText in your $watch. Check the network console in Chrome to see the ajax calls as you type.
My HTML:
<html ng-app="TestApp">
<head lang="en">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Просмотр списка адресов</title>
<link rel="stylesheet" type="text/css" href="~/Content/ng-grid.css" />
<link rel="stylesheet" type="text/css" href="~/Content/style.css" />
<script src="~/Scripts/jquery-1.9.1.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/ui-bootstrap.js"></script>
<script src="~/Scripts/ng-grid.js"></script>
<script src="~/Scripts/main.js"></script>
</head>
<h2>Просмотор списка адресов</h2>
<body ng-controller="MainController">
<div class="gridStyle" ng-grid="gridOptions">
</div>
</body>
Data from server:
[{"id":1,"country":"Россия","city":"Ульяновск","street":"Ленина, ул.","house":1,"zipcode":432071,"datec":"10.04.2014, 12:21"},{"id":2,"country":"Россия","city":"Ульяновск","street":"Нариманова, пр-т.","house":2,"zipcode":432072,"datec":"15.03.2012, 15:34"},{"id":3,"country":"Россия","city":"Москва","street":"Киевский, пр-т.","house":5,"zipcode":123123,"datec":"01.05.2014, 23:00"}]
$scope.$watch working correctly with filterOptions and with filterOptions.filterText too.
So the grid renders correctly initially. Is the issue that when you type in the country filter input it does send an ajax request but doesn't update $scope.addresses when the data is received?
Or is it that you're calling $scope.update() some other way?
Grid renders correctly initially. $scope.$watch update $scope.addresses by ajax request and we can see data by alert(JSON.stringify($scope.addresses)) in $scope.update(). I think, $scope.gridOptions.data doesn't update.
Maybe try stepping through your debugger. From my end nothing that could be causing this stands out.
$scope.gridOptions.data is just the string of the scope property that the grid should watch for changes.
Yeah, $scope.gridOptions.data updated by ajax request. Maybe problem with call of grid render. ng-table work with this ajax call and updating data in table.
Is it possible that you could modify your update statement to reset the data in the grid, as such:
$scope.update = function () {
$http.get('/Home/GetData', {
params: { filter: $scope.filterOptions.filterText }
})
.then(function (result) {
$scope.addresses = result.data;
$scope.gridOptions.data = 'addressData';
//alert(JSON.stringify(result))
})
$scope.$apply()
That may trigger a refresh.
Alternatively, have you worked through the plunker that @c0bra provided?
Information request provided, and no further comments for at least 2 weeks. Closing on assumption that the raiser has resolved the issue.
I'm having the same issue. Was anyone able to resolve this? If so please share...
I am doing a POST w/ success handler. Inside success handler I then set the grid data. The grid data doesn't change after the initial load.
Hi, benjamin0101, maybe angular.copy(source, destination) can be helpful. https://docs.angularjs.org/api/ng/function/angular.copy
@batuuu thanks for the suggestion
I'm seeing the above problem too. I've also tried calling notifyDataChange('all') and refresh() but the rows inside the gird always maintain the original set of rows given - not the new set of rows. The original plunkr still demonstrates the issues I think.
Any progress on this issue? I've run into the same difficulty where re-assigning $scope.gridOptions.data does not cause the grid to refresh. I can log and see that the underlying data is changing correctly.
a) comments on closed issues can easily get missed. If the issue is closed that usually means we think it is resolved
b) what version are you using - ng-grid or ui-grid?
c) usually the problem is one of pointers and objects - if you assign your data as $scope.gridOptions.data = myData, the grid will grab a pointer to that data. If you later do $scope.gridOptions.data = myOtherData, you've changed where $scope.gridOptions.data is pointing, but the grid still has a pointer to the old object. You need to either use:
$scope.data = myData;
$scope.gridOptions.data = 'data';
or you need to empty and refill the original array:
$scope.gridOptions.data.length = 0;
angular.forEach( $scope.myOtherData, function( row ) {
$scope.gridOptions.data.push( row );
});
a) Woops
b) ui-grid 3.0.0 rc-16
c) I tried both your suggestions to no avail. I can't even get it to change when I zero the length of the array stored in $scope.gridOptions.data (I can see the array stored there is empty when I log it to console)
Changing the data should just work - it's in one of the tutorials (sorry, away from my computer and can't remember which one).
What is it exactly doing? Do you have data and its displaying, then you change it and no update? Could you provide a plunker (perhaps based on the tutorial)?
The tutorial is: http://ui-grid.info/docs/#/tutorial/112_swapping_data
I'm also getting same problem. It's not updating ... I tried with different way nothing work so far. Any progress on this issue?
The issue is closed on the basis that it works in the tutorial. So unless you have a plunker demonstrating a problem, the assumption is it's a problem in your code not a ui-grid issue.
I have this issue with editing a row.column value That is not covered by the tutorial.
I tried resetting the data instead, but that does not work either same as the others.