0

I have a nested ng-repeat. I want to arrange order of the inside list by dynamic options.

i.e. the sort_option value is from $scope variable getting dynamically. This will give all inside ul list are in sorted order, but I want to sort only one list inside the loop.

<ul>
<li ng-repeat='itemsli in mylists.lists'>
 <ul>
 <li ng-repeat="item in list | orderBy: sort_option | filter: {due_date_time : current_date_time}">
  {{item.name}}
 </li>
</ul>
</li>
</ul>
0

4 Answers 4

1

change the line like this, add : true at the end of filter

 <li ng-repeat="item in list | orderBy: sort_option | filter: {due_date_time : current_date_time}: true ">
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure that I understand you correctly

but I created sample code like yours and seem like it works fine

the lists are

$scope.firstLists = [{id: 2},{id: 1},{id: 3}];
$scope.secondLists = [{id: 2},{id: 1},{id: 3}];

with

<ul>
<li ng-repeat='itemsli in firstLists'>
  <ul>
     <li ng-repeat="item in secondLists | orderBy: 'id'">
     {{item.id}} of {{itemsli.id}}
     </li>
  </ul>
</li>
</ul>

and the result is

1 of 2
2 of 2
3 of 2
1 of 1
2 of 1
3 of 1
1 of 3
2 of 3
3 of 3

Comments

0

Are you looking for this kind of nested ng-repeat?

var app = angular.module('soApp', []);
app.controller('soController', function ($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
    $scope.sortby_cards = function (sort_value) {
        console.log(sort_value);
        $scope.sort_option = sort_value;
    };
    $scope.firstLists = [{name: "def", vote: 2}, {name: "ret", vote: 1}, {name: "ghj", vote: 3}];
    $scope.secondLists = [{name: "pqr", vote: 2, attachment_count: 1},
        {name: "abc", vote: 1, attachment_count: 3},
        {name: "xyz", vote: 3, attachment_count: 2}];
});

Comments

0

I found a solution based on Farzad Salimi Jazi's answer:

<ul>
<li ng-repeat='lists in mylists.lists'>
<md-button ng-click="sortby_cards('vote', lists)">Sort by votes</md-button>
<md-button ng-click="sortby_cards('attachment_count', lists)">Sort by Attachments
</md-button>

 <ul>
 <li ng-repeat="item in list | orderBy: list.sort_option | filter: {due_date_time : current_date_time}">
  {{item.name}}
 </li>
</ul>
</li>
</ul>

In controller:

$scope.sortby_cards = function(sort_value,list){
    $scope.sort_option = sort_value;
    $scope.sort_index_val = index_val;
    list.sort_option = sort_value;
  }

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.