0

I have a list and I want to sort my items with a filter, where it is shown from highest to lowest according to the score of each person. I just want to show the top 8 of the 13 that exist. I would like to have a grid showing the highest to lowest score from left to right. enter image description here

I can increase the score of a person by clicking on the 'sum score' button and entering the index of the object. I have no idea how to have this grid by default and that only people change.

<span ng-repeat='item in list | orderBy: "-score"'>
<p style='display:{{$index>7?"none":"block"}}'>
  {{item.name}} score {{item.score}}
</p>
</span>
<h2>index min 0 - max 12</h2>
<button ng-model='btn' ng-click='sumKey()'>Sum Score</button>
<input type='number' ng-model='mytext' max=12 min=0>  

$scope.list=[
 {'name': 'pedro', 'score':1},
  {'name': 'miguel', 'score':2},
  {'name': 'juan', 'score':3},
  {'name': 'david', 'score':4},
  {'name': 'yeison', 'score':5},
  {'name': 'doraemon', 'score':6},
  {'name': 'goku', 'score':7},
  {'name': 'vegeta', 'score':8},
  {'name': 'seiya', 'score':9},
  {'name': 'bruno', 'score':10},
  {'name': 'faver', 'score':11},
  {'name': 'cane', 'score':12},
  {'name': 'brye', 'score':13}
]

http://jsfiddle.net/bLrft3nx/

Thank you

5
  • Are you using any frontend libraries, like Bootstrap or Material design? Commented Aug 26, 2017 at 3:09
  • @tavnab only bootstrap.. Commented Aug 26, 2017 at 3:14
  • @tavnab I only use the class .row .cols ... Commented Aug 26, 2017 at 3:14
  • Try this jsfiddle.net/bLrft3nx/1 Commented Aug 26, 2017 at 3:21
  • @yogendarji it not works... Commented Aug 26, 2017 at 3:27

1 Answer 1

1

For the limiting to the top 8, you can use the limitTo filter:

<span ng-repeat='item in list | orderBy: "-score" | limitTo: 8'>
  <p>
    {{item.name}} score {{item.score}}
  </p>
</span>

For the grid, since you mentioned Bootstrap (I'll assume 3.x, but it should apply to other versions), you can define a single row with multiple columns of class col-md-3 (and other sizes if you want to be responsive). This will effectively create a grid with 4 columns per row (since the Bootstrap grid is 12 slots wide, and it'll wrap to the next line every 12 / 3 = 4 columns).

<div class="row">
  <div class="col-xs-3" ng-repeat='item in list | orderBy: "-score" | limitTo: 8'>
    <p>
      {{item.name}} score {{item.score}}
    </p>
  </div>
</div>

Update

Here's a jsfiddle that demonstrates it. I also added classes col-sm-3 and col-xs-3 to account for the small size of the preview area; you can include all of the col-*-3 classes if you want to ensure it's always a grid, regardless of viewport size.

Update 2

You can just replace col-md-3 with col-xs-3 if you want the grid to apply to all viewport sizes; no need to add all the col-*-3 classes. The snippet above has been updated, and here's another jsfiddle.

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

2 Comments

thanks, I tried your code but not works.. jsfiddle.net/t8emvq5w
I suspect it was because of the small preview area of jsfiddle. See my update.

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.