1

I need help creating a dynamic table in the format of a round robin competition using HTML and AngularJS. An array of strings will be given and then the table will be created based on how many names were in the list so part of the table will be generated dynamically and part of the table will always be the same. This is an example of a table that would be generated if I passed an array with 8 names. Only columns A, B, and C should have any information when the table is generated though I kept everything blank for simplicity's sake. The rest of the boxes should all be text input fields.

Until now most of the tables I have done have been pretty simple and I am a little out of my depth here, any help would be much appreciated.

enter image description here

2 Answers 2

1

Assuming you always have a full 8 teams this would get you started

<table>
  <tr>
    <th>club</th>
    <th>team</th>
    <th>#</th>
    <th ng-repeat="item in items">{{$index+1}}</th>
    <th>V</th>
    <th>TS</th>
  </tr>
  <tr ng-repeat="item in items">
    <td>{{item.club}}</td>
    <td>{{item.team}}</td>
    <td>{{item.rank}}</td>
    <td ng-repeat="item in items" ng-class="{black:$index==$parent.$index}"></td>
    <td><input ng-model="item.v"></td>
    <td><input ng-model="item.ts"></td>
  </tr>
</table>

DEMO

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

4 Comments

This was very helpful however the snippet ng-class="{black:$index==$parent.$index}" does not shade the boxes black like I would expect, in fact it does not appear to do anything. Is the syntax correct?
works fine in my demo doesn't it? You have to use a css rule for that class
it was a formatting error when copied in, thanks for the help!
should consider accepting an answer sometime if they helped you
0

This is a really nice example of using nested ng-repeat elements.

Please see this plunker for a working demo.

The main trick for detecting when to black out a box is to use ng-init="$rowIndex=$index" on the outer ng-repeat (where we generate a row for each entry). This allows the inner ng-repeat (where we generate a column for each entry) to have an ng-class="{'blackout': $index==$rowIndex}"

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.