Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm trying to load data in one ui grid table from two json files, but there are data only from one file.

I've prepared two arrays for the both json files.

$scope.sourceOne = [];
$scope.sourceTwo = [];

Then I've loaded data with $http service

$http.get('SourceOne.json').success(function (data) {
    data.forEach( function( row, index ) {
        $scope.sourceOne.push(data);
    });
    $scope.gridOptions.data = data;
    console.log('data from SourceOne.json', data);
});

$http.get('SourceTwo.json').success(function (data) {
    data.forEach( function( row, index ) {
        $scope.sourceTwo.push(data);
    });
    $scope.gridOptions.data = data;
    console.log('data from SourceTwo.json', data);
});

and at the I've tried to concatenate these two arrays and show as a result in the grid.

$scope.myConcatenatedData = $scope.sourceOne.concat($scope.sourceTwo);

Pls take a look at the plunker

share|improve this question
up vote 0 down vote accepted

Firstly there is an erron in the forEach loops (row as data item inside loop):

data.forEach( function( row, index ) {
    $scope.sourceOne.push(row);
});

and then you have to be sure that 2nd data group is loaded after the first one.

Besides concatenation of two data set must be after 2nd group is loaded, inside success handler.

Check my edited Plunker: https://plnkr.co/edit/tZ1kPgNGiceTfWcrQm2y?p=preview

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.