3

I'm trying to create a two col layout with ng-repeat.

<div class="row">
   <div class="col-md-6" ng-repeat="item in items">
       Item: {{item}}
   </div>
</div>

This results in the following problem:

enter image description here

P.S. This problem has been answered before with native CSS cols but I want to do it with bootstrap.

P.S. The solution proposed below is not working.. anyone got any other ideas please?

2 Answers 2

11

You'll have to break it into two seperate columns, but it should be pretty easy after that:

<div class="row">
   <div class="col-md-6" ng-repeat="item in items | limitTo: items.length /2: 0">
       Item: {{item}}
   </div>
   <div class="col-md-6" ng-repeat="item in items | limitTo: items.length /2: items.length /2">
       Item: {{item}}
   </div>   
</div>
Sign up to request clarification or add additional context in comments.

6 Comments

thanks! exactly the kind of solution i wanted because everything is handled in the view!
hi, is there a way to extend it to 3, 4 columns? I know I can always type "col-md-4" and change limit to items.length / 3, but i think it may possible to do so with nested ng-repeats with variable number of cols!
p.s. sorry one more thing.. i think items.length /2, gets Math.floor and it leaves out the last element. Is it okay to add +1 to it?
please see this plunkr: plnkr.co/edit/GdV116QqeawGpVOTHI25?p=preview there are 5 items, but it renders only the first four?
You're right, should just be able to get around that by adding 1. plnkr.co/edit/jkG6B51OBcvXsTNeOz8H?p=preview
|
0

for that i'm taken two tables keep bootstrap styles

<table> <tr ng-repeat="cl in codelist" ng-if="$index<codelist.length/2">
                            <td>{{$index}}</td>

                        </tr></table>
<table> <tr ng-repeat="cl in codelist" ng-if="$index>=codelist.length/2">
                            <td>{{$index}}</td>

                        </tr></table>

that it show order by ordey 1 3 2 4 5 6 like this

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.