2016-09-21 32 views
0

不更新数据最初数据为空但后来在setPagingData()方法时得到更新。经过数据在控制台和$ scope.Data正在得到更新。但网格中的数据没有得到更新。任何帮助..纳克网格在网格

class GridViewController { 

    constructor($scope,$timeout) { 
    $scope.gridView = { 
      show : true 
     }; 

    $scope.columnDefs = [ 
      {field : 'Id' , displayName : 'ID'}, 
      {field : 'name' , displayName : 'Name'} 
     ]; 
    $scope.fData = [ 
     { 
     "Id" : "123", 
     "name": "John" 
     } 
    ] 
    $scope.filterOptions = { 
    filterText: "", 
    useExternalFilter: true 
    }; 
    $scope.totalServerItems = 0; 
    $scope.Data = []; 
    $scope.pagingOptions = { 
    pageSizes: [250, 500, 1000], 
    pageSize: 5, 
    currentPage: 1 
    }; 

    $scope.setPagingData = function(data, page, pageSize){ 
    var pagedData = data.slice((page - 1) * pageSize, page * pageSize); 
    $scope.Data = angular.copy(pagedData); 
    console.log($scope.Data); 
    $scope.totalServerItems = data.length; 
    if (!$scope.$$phase) { 
     $scope.$apply(); 
    } 
    $scope.$apply(); 
    }; 

    $scope.getPagedDataAsync = function (pageSize, page, searchText) { 
    $timeout(function() { 
     var data; 
     if (searchText) { 
      var ft = searchText.toLowerCase(); 
      data = $scope.fData.filter(function(item) { 
        return JSON.stringify(item).toLowerCase().indexOf(ft) != -1; 
       }); 
      $scope.setPagingData(data,page,pageSize); 
     } else { 
       $scope.setPagingData($scope.fData,page,pageSize); 
     } 
    }, 100); 
    }; 

    $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage); 

    $scope.$watch('pagingOptions', function (newVal, oldVal) { 
    if (newVal !== oldVal && newVal.currentPage !== oldVal.currentPage) { 
     $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText); 
    } 
    }, true); 
    $scope.$watch('filterOptions', function (newVal, oldVal) { 
    if (newVal !== oldVal) { 
     $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText); 
    } 
    }, true); 
    //console.log($scope.Data.length); 
    $scope.gridOptions = { 
    data : 'Data', 
    columnDefs : $scope.columnDefs, 
    enablePaging: true, 
    showFooter: true, 
    totalServerItems: $scope.totalServerItems, 
    pagingOptions: $scope.pagingOptions, 
    filterOptions: $scope.filterOptions, 
    rowHeight: 28, 
    plugins: [new ngGridFlexibleHeightPlugin()] 
    }; 
    gridViewScope = $scope; 
    } 
} 
orderFlowApp.controller('GridViewController', GridViewController); 

回答

0

是的,似乎有一个NG网格的问题。尝试这样的事情。

$scope.gridOptions.data = []; 

$timeout(function() { 
    $scope.gridOptions.data = $scope.Data; 
}); 
+0

这并没有帮助@Vikash。我试过了。 –