angular-ui/ui-grid

function dataWatchFunction: sometimes the grid is empty even though there is data

Open

#3.804 geöffnet am 18. Juni 2015

Auf GitHub ansehen
 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (2.496 Forks)batch import
help wantedneeds: analysis

Repository-Metriken

Stars
 (5.395 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

Hi,

I'm currently using ui-grid (v3.0.0-rc.20 - 2015-02-24) and I'm loading my data asynchronously. Sometimes the grid is empty even though I know there is data.

This is how I set grid data in my controller:

$scope.gridOptions.data = 'workflowJobs';

Later, in my controller, I get my data asynchronously:

getWorkflowJobs().then(function(jobs){
    $scope.workflowJobs = jobs;
});

After investigation I found that the dataWatchFunction is called each time $scope.uiGrid.data changes. dataWatchFunction function is called twice: Once, when initializing the grid (and considering there is 0 items). Twice, when I have my data.

However, inside this dataWatchFunction function (line 2627 for the version I have), we have a $q.all(promises) that modifies the table with the variable newData.

I added two logs around line 2627:

...
          console.log("before promise with " + newData.length);
          $q.all(promises).then(function() {
            console.log("after promise with " + newData.length);
            self.grid.modifyRows(newData)
...

Which indeed sometimes gives the following output: "before promise with 0" ui-grid.js:2626:10 "before promise with 25" ui-grid.js:2626:10 "after promise with 25" ui-grid.js:2628:12 "after promise with 0" ui-grid.js:2628:12

which gives an empty grid.

I haven't read more to fully understand how it could be fixed or what could be impacted, but at least it's known.

Cheers

Contributor Guide