Search code examples
angularjsangularjs-ng-repeatchecklist-model

Get ng-repeat data to appear in 4 columns


I'm getting list of data from Db to a view using ng-repeat. In order to select multiple values at once I'm using checklist-model. My code is as follows,

<div ng-repeat="item in items">
<input type=checkbox checklist-model="user.role" checklist-value="item"/>{{item}}
</div> 

This will return a long list one below another. What I need is to get these data in the list to be displayed in 4 columns. Any help please!


Solution

  • Working Demo

    This is what you are looking for. Hope that solve your problem.

     <div ng-repeat="product in products" ng-if="$index % 3 == 0" class="row">
        <div class="col-xs-4"> <input type="checkbox" checklist-model="user.role" checklist-value="{{products[$index]}}"/>{{products[$index]}}</div>
        <div class="col-xs-4"> <input type="checkbox" checklist-model="user.role" checklist-value="{{products[$index]}}"/>{{products[$index+1]}}</div>
        <div class="col-xs-4"> <input type="checkbox" checklist-model="user.role" checklist-value="{{products[$index]}}"/>{{products[$index+2]}}</div>
    </div>
    

    Output:

    enter image description here