0

I'm trying to display data in 3 column table format.

With the below code am able to get data in 3 column format but I want it in proper table, with tr and td.

 <body ng:app="myApp" ng:controller="myCtrl">
    <span ng:repeat="(index, value) in array">
        {{value}}<br ng:show="(index+1)%3==0" />
    </span>
</body>

and

    lvar app = angular.module('myApp', []);

app.controller('myCtrl', function ($scope) {
    $scope.array = ["opt1","opt2","opt3","opt4","opt5","opt6","opt7"];
});

Fiddle: http://jsfiddle.net/JG3A5/

I tried but with ng-repeat I'm not able to achieve it properly. Can someone help me out with this?

2
  • You're using the repeat syntax for an object, arrays are simply item in items - are you able to change the format of your data? Commented Apr 13, 2015 at 15:57
  • You can use 'track by $index' instead to get the index Commented Apr 13, 2015 at 16:01

1 Answer 1

3

If you can change your data format, it'd certainly be easier to have an array of arrays, each inner array representing a row:

$scope.data = [
    ["opt1", "opt2", "opt3"],
    ["opt1", "opt2", "opt3"],
    ["opt1", "opt2", "opt3"]
];

You could then do a simple inner ng-repeat

<table>
    <tr ng-repeat="row in data">
        <td ng-repeat="column in row">{{column}}</td>
    </tr>
</table>

Demo: http://jsfiddle.net/JG3A5/75/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.