Angular js UI grid is not getting updated with new content

我是研究僧i 提交于 2019-12-25 03:58:27

问题


I am calling $http.get to get new content from the server for angular ui grid. On change of date in the datepicker I trigger an ng-change event to make another http call to get new content. The call is successful but the grid is not updated with new content.$scope.grid.core.notifyDataChange() throws error when called inside the http success call back.Please suggest ways to update the grid with new content.

Please find the plnkr code. when I click load button, I want to update grid with new JSON data using http call but it is not updating grid. http://plnkr.co/edit/S2A3scEoO6QIGFbru3Lr?p=preview


回答1:


The problem with your example is inside $http's success method(lines 256-260).

$http.get(...).success(
  function(data){
    $scope.roData = data;
});

There you are just putting your data inside a scope property ($scope.roData), but then you're not doing anything with that scope property.

Furthermore you're trying to assign a wrong value to uiGrid.gridOptions.data with the lines:

if($scope.gridOptions.data ==='rData'){
  $scope.gridOptions.data = 'roData';
}

But you did 2 mistakes:

  1. Treating variables as string, and this is not going to work. Inside your JS files you need to access your scope with $scope.nameOfVariable not by using their names as strings like 'nameOfVariable'.

  2. You put these lines outside of your success method, so they are executed before you actually get your data.

I managed to edit your plunker and make it work, you can find it here. What I did was putting your lines together and fix the name error. I did not put there any if since I don't know what logic you wanted to accomplish.

$http.get(...).success(
  function(data){
    $scope.roData = data;
    $scope.gridOptions.data = $scope.roData;
});


来源:https://stackoverflow.com/questions/33705680/angular-js-ui-grid-is-not-getting-updated-with-new-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!