2016-03-27 26 views
0

Raporları oluşturmam gerekir. Angularjs ve PHP'yi kullanıyorum.
Beklenen Çıktı:Köşeli verileri dikey olarak açısal js kullanarak yatay olarak gösterme

Spec_ID  Bot_Name        Color    Colorno     Screen 

AN/SN/18 750ML POCO PESCA ROTATION 1 Light Buff Dark Buff Red P1345C P135C P warm red 150-31 150-31 150-31 

Gerçek Çıktı:

AG/SN/18 750ML POCO PESCA ROTATION 1 Light Buff P1345C 150-31 
AG/SN/18 750ML POCO PESCA ROTATION 1 Dark Buff P135C  150-31 
AG/SN/18 750ML POCO PESCA ROTATION 1 Red  P Warm Red 150-31 

HTML:

<table> 
    <thead> 
     <tr> 
      <th>Spec_ID</th> 
      <th>name</th> 
      <th>lastname</th> 
      <th>Rollno</th> 
      <th>Color</th> 
      <th>Color No</th> 
      <th>Mesh</th>       
    </thead> 
    <tbody> 
     <tr ng-repeat="user in users"> 
      <td>{{user.Spec_Id}}</td> 
      <td>{{user.Name}}</td> 
      <td>{{user.lastname}}</td> 
      <td>{{user.Rollno}}</td> 
      <td>{{user.color}}</td> 
      <td>{{user.colorno}}</td> 
      <td>{{user.Mesh}}</td> 
     </tr> 
    </tbody> 
</table> 

SCRIPT

var request=$http({ 
    method: "post", 
    url:"stock.json", 
    data: { 
    master: $scope.cust 
    } 

}); 
request.success(function(response){ 
    $scope.users = response; 
    //ajax request to fetch data into $scope.data 
}); 

stock.json:

Array 
(
    [0] => Array 
     (
      [0] => AG/SN/18 
      [Spec_Id] => AG/SN/18 
      [1] => 750ML POCO PESCA ROTATION 1 
      [Bot_Name] => 750ML POCO PESCA ROTATION 1 
      [2] => Light Buff 
      [color] => Light Buff 
      [3] => P1345C 
      [colorno] => P1345C 
      [4] => 150-31 
      [screen] => 150-31 
     ) 

    [1] => Array 
     (
      [0] => AG/SN/18 
      [Spec_Id] => AG/SN/18 
      [1] => 750ML POCO PESCA ROTATION 1 
      [Bot_Name] => 750ML POCO PESCA ROTATION 1 
      [2] => Dark Buff 
      [color] => Dark Buff 
      [3] => P135C 
      [colorno] => P135C 
      [4] => 150-31 
      [screen] => 150-31 
     ) 

    [2] => Array 
     (
      [0] => AG/SN/18 
      [Spec_Id] => AG/SN/18 
      [1] => 750ML POCO PESCA ROTATION 1 
      [Bot_Name] => 750ML POCO PESCA ROTATION 1 
      [2] => Red 
      [color] => Red 
      [3] => P Warm Red 
      [colorno] => P Warm Red 
      [4] => 150-31 
      [screen] => 150-31 
     ) 

) 

Verileri dikey olarak göstermek yerine, verileri yatay olarak göstermelidir. Lütfen bana öneride bulunun. Teşekkürler.

+0

Eğer http://stackoverflow.com/questions/36238379/nested-ng-repeat-in-angular-js-table/36238460#36238460 –

+0

sizin ng-tekrarlamak olduğu yardım olabilir? etiketi –

+0

@ hadiJZ üzerinde olmalıdır. Çok teşekkürler, ama bu benim için işe yaramadı. renk, colorno ve ekran üç farklı sütun tablosudur. – user007

cevap

0

Verileri denetleyicide hazırlar ve onu yeni bir diziye eklerim.

angular.module('app', []) 
.controller('mainController', ['$scope', '$filter', function($scope, $filter) { 
$scope.data = [{ 
    'Spec_Id': 'AG/SN/18', 
    'Bot_Name': '750ML POCO PESCA ROTATION 1', 
    'color': 'Light Buff', 
    'colorno': 'P1345C', 
    'screen': '150-31' 
    }, { 
    'Spec_Id': 'AG/SN/18', 
    'Bot_Name': '750ML POCO PESCA ROTATION 1', 
    'color': 'Dark Buff', 
    'colorno': 'P135C', 
    'screen': '150-31' 
    }, { 
    'Spec_Id': 'AG/SN/18', 
    'Bot_Name': '750ML POCO PESCA ROTATION 1', 
    'color': 'Red', 
    'colorno': 'P Warm Red', 
    'screen': '150-31' 
    }] 
    var cleanData = function(){ 
    console.log("calling clean data"); 
    $scope.cleanData = []; 
    var id = ''; 
    $scope.data = $filter('orderBy')($scope.data, 'Spec_Id', false); 
    var cleanDataIndex = 0; 
    for(var i = 0; i < $scope.data.length; i++){ 
     var obj = $scope.data[i]; 
     if(id !== obj.Spec_Id){ 
     id = obj.Spec_Id; 
     obj.colorList = obj.color; 
     obj.colornoList = obj.colorno; 
     obj.screenList = obj.screen; 
     $scope.cleanData.push(obj); 
     }else{ 
     var newObj = $scope.cleanData[cleanDataIndex]; 
     newObj.colorList += ","+obj.color; 
     newObj.colornoList += ","+obj.colorno; 
     newObj.screenList += ","+obj.screen; 
     } 
    } 
    } 
    cleanData(); 
}]); 

Görüntülemek için aşağıdakileri kullanırdım.

<html ng-app='app' ng-controller='mainController'> 
<body> 
    <div class="container"> 
    <div class="jumbotron"> 
     <table class="table table-bordered"> 
     <thead> 
      <tr> 
      <th>Spec Id</th> 
      <th>Bot Name</th> 
      <th>Color</th> 
      <th>Color No</th> 
      <th>Screen</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr ng-repeat="row in cleanData"> 
      <td>{{row.Spec_Id}}</td> 
      <td>{{row.Bot_Name}}</td> 
      <td>{{row.colorList}}</td> 
      <td>{{row.colornoList}}</td> 
      <td>{{row.screenList}}</td> 
      </tr> 
     </tbody> 
     </table> 
    </div> 
    </div> 
</body> 
</html> 
İlgili konular