0

How can i add such this to ui-grid? I have a .Json with below format :

0:["date","numberOfTransaction", "price"]
1:["20170207", "3029223", "5294194476028"]
2:["20170208", "2176469", "1479374036275"]
3:["20170209", "2902111", "6971208095034"]
4:["all", "8107803", "13744776607337"]
Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62
Saeed Aliakbari
  • 281
  • 4
  • 20

2 Answers2

1

You should init ui-grid option manually. i.e you should init columnDefs and data array of ui-grid.

Like to this.

  angular.forEach($scope.myData,function(data,j){
    angular.forEach(data,function(d,i){
      if(j ==  0)
          $scope.gridOptions.columnDefs.push({field:d});
     else if(i == 0){
        var date = $scope.gridOptions.columnDefs[0];
        var numberOfTransaction = $scope.gridOptions.columnDefs[1];
        var price = $scope.gridOptions.columnDefs[2];
    $scope.gridOptions.data.push({date:data[0],numberOfTransaction:data[1],price:data[2]});
  }  
  }  
 })
})

Demo

Hadi J
  • 16,989
  • 4
  • 36
  • 62
0

if your JSON is an object you need to access it by the property name.

 <div ng-app="app" ng-controller="ctrl">
     {{arr['0']}}
 </div>

angular.module("app",[])
.controller("ctrl",function($scope){
$scope.arr = {0:["date","numberOfTransaction", "price"],
1:["20170207", "3029223", "5294194476028"],
2:["20170208", "2176469", "1479374036275"],
3:["20170209", "2902111", "6971208095034"],
4:["all", "8107803", "13744776607337"]}

})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 {{arr['0']}}
</div>
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80