angular-ui/ui-grid

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

Open

#3804 aperta il 18 giu 2015

Vedi su GitHub
 (4 commenti) (0 reazioni) (0 assegnatari)JavaScript (2496 fork)batch import
help wantedneeds: analysis

Metriche repository

Star
 (5395 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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

Guida contributor