Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9067869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:03:03+00:00 2026-06-16T17:03:03+00:00

I’m using angular.js and (for the sake of argument) bootstrap. Now I need to

  • 0

I’m using angular.js and (for the sake of argument) bootstrap. Now I need to iterate on “things” and display them in ”rows” :

<div class="row">
  <div class="span4">...</div>
  <div class="span4">...</div>
  <div class="span4">...</div>
</div>
<div class="row">
  etc...

Now, how can I close my .row div on every third thing with angular? I tried ui-if from angular-ui but even that doesn’t make it.

If I were to use server-side rendering, I would do something like this (JSP syntax here, but does not matter) :

<div class="row>
  <c:forEach items="${things}" var="thing" varStatus="i">
    <div class="span4">
        ..
    </div>
  <%-- Here is the trick:--%>
  <c:if test="${i.index % 3 == 2}">
          </div><div class="row">
  </c:if>
  </c:forEach>
</div>

Note that I need to actually alter the DOM here, not just css-hiding elements. I tried with the repeat on the .row and .span4 divs, with no avail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:03:04+00:00Added an answer on June 16, 2026 at 5:03 pm

    Edit Nov 12, 2013

    It seems that not only did angular change a little in 1.2, but that there is an even better method. I’ve created two filters. I tried to combine them into one but got digest errors. Here are the two filters:

    .filter("mySecondFilter", function(){
        return function(input, row, numColumns){
            var returnArray = [];
            for(var x = row * numColumns; x < row * numColumns + numColumns; x++){
                if(x < input.length){
                    returnArray.push(input[x]);                    
                }
                else{
                    returnArray.push(""); //this is used for the empty cells
                }
            }
            return returnArray;   
        }
    })
    .filter("myFilter", function(){
        return function(input, numColumns){
            var filtered = [];
            for(var x = 0; x < input.length; x++){
                if(x % numColumns === 0){
                    filtered.push(filtered.length);
                }
            }
            return filtered;
        }
    });
    

    And now the html will look like this:

    <table border="1">
         <tr data-ng-repeat="rows in (objects | myFilter:numColumns)">
              <td data-ng-repeat="column in (objects | mySecondFilter:rows:numColumns)">{{ column.entry }}</td>
         </tr>  
    </table>
    

    jsFiddle: http://jsfiddle.net/W39Q2/


    Edit Sept 20, 2013

    While working with lots of data that needed dynamic columns I’ve come up with a better method.

    HTML:

    <table border="1">
        <tr data-ng-repeat="object in (objects | myFilter:numColumns.length)">
            <td data-ng-repeat="column in numColumns">{{ objects[$parent.$index * numColumns.length + $index].entry }}</td>
        </tr>  
    </table>
    

    Javascript:

    $scope.objects = [ ];
    for(var x = 65; x < 91; x++){
        $scope.objects.push({
            entry: String.fromCharCode(x)
        });
    }
    
    $scope.numColumns = [];
    $scope.numColumns.length = 3;
    

    New Filter:

    .filter("myFilter", function(){
        return function(input, columns){
            var filtered = [];
            for(var x = 0; x < input.length; x+= columns){
                 filtered.push(input[x]);   
            }
            return filtered;
        }
    });
    

    This allows it to be dynamic. To change the columns just change the numColumns.length. In the js fiddle you can see I’ve wired it up to a dropdown.

    jsFiddle: http://jsfiddle.net/j4MPK/


    Your html markup would look like this:

    <div data-ng-repeat="row in rows">
        <div data-ng-repeat="col in row.col">{{col}}</div>
    </div>
    

    And then you could make a variable in your controller like so:

    $scope.rows = [
        {col: [ 1,2,3,4 ]},
        {col: [ 5,6,7 ]},
        {col: [ 9,10,11,12 ]}
    ]; 
    

    This way, you can have any number of columns you want.

    jsfiddle http://jsfiddle.net/rtCP3/39/


    Edit I’ve modified the fiddle to now support having a flat array of objects:

    jsfiddle: http://jsfiddle.net/rtCP3/41/

    The html now looks like this:

    <div class="row" data-ng-repeat="row in rows">
        <div class="col" data-ng-repeat="col in cols">
            {{objects[$parent.$index * numColumns + $index].entry}}
        </div>
    </div>  
    

    And then in the controller i have:

    $scope.objects = [
        {entry: 'a'},
        {entry: 'b'},
        {entry: 'c'},
        {entry: 'd'},
        {entry: 'e'},
        {entry: 'f'},
        {entry: 'g'},
        {entry: 'h'}    
    ];
    
    $scope.numColumns = 3;
    $scope.rows = [];
    $scope.rows.length = Math.ceil($scope.objects.length / $scope.numColumns);
    $scope.cols = [];
    $scope.cols.length = $scope.numColumns;
    

    The $scope.numColumns variable is used to specify how many columns you want in each row.


    To handle dynamic array size changes, put a watch on the length of the array (not the whole array, that would be redundent)

    $scope.numColumns = 3;  
    $scope.rows = [];    
    $scope.cols = [];    
    $scope.$watch("objects.length", function(){
        $scope.rows.length = Math.ceil($scope.objects.length / $scope.numColumns);
        $scope.cols.length = $scope.numColumns;        
    });
    

    jsfiddle: http://jsfiddle.net/rtCP3/45/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
I have thousands of HTML files to process using Groovy/Java and I need to
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
this is what i have right now Drawing an RSS feed into the php,
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.