D
D
Demigodd2019-05-02 09:51:23
JavaScript
Demigodd, 2019-05-02 09:51:23

How to sort multiple elements by different keys in ng-repeat -> orderBy?

Link to JSFiddle .
For example, there is an array of users, firstName and lastName.
When rendering them in the frontend using ng-repeat, I sort them by the key firstName . But here are some of them that need to be sorted by lastName.
So now the result is this.

$scope.users = [{
      firstName: 'AAA',
      lastName: 'AAA'
    }, {
      firstName: 'BBB_test',
      lastName: 'EEE'
    }, {
      firstName: 'CCC',
      lastName: 'CCC'
    }, {
      firstName: 'DDD_test',
      lastName: 'WWW'
    }];

// output
AAA
BBB_test
CCC
DDD_test

For the name BBB_test and DDD_test during sorting, you need to take not firstName but lastName .
// Expect Result
AAA
CCC
BBB_test
DDD_test

How to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2019-05-02
@Demigodd

https://developer.mozilla.org/en/docs/Web/JavaScript...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question