Gold100 Gold100 - 5 months ago 242
AngularJS Question

How to Save Selection in Angularjs UI - Grid

I built this

ui-grid
that updates every 3 seconds:

function updateGrid() {
dFactory.getData().then(function(data) {
$scope.gridOptions.data = data;
});


The data updates just fine, but the selection deletes itself, the rows I select before just won't save.

I have tried:


  1. Putting primary key - didn't help

  2. Saving state and restore it after update - didn't help

  3. Manually select rows after update - didn't help



What can i do?

Answer

This is how i solved it:

var state = $scope.gridApi.saveState.save();
                $scope.mydata = response.data;

                $timeout(function() {
                    $scope.gridApi.saveState.restore($scope, state);
                }, 1);
Comments