noobcoder noobcoder - 1 year ago 89
AngularJS Question

Angular orderBy to also order the original array

New to Angular, I ham using angular's

on a column header as the code snippet mentioned in my earlier post: AngularJS orderby not working as expected

Now in my controller, the array
is still going to maintain its original order as it came from the backend and orderBy directive is just going to order the DOM as per the sorting criteria. I want to know how do I extract the top row after every re-ordering from the DOM ? This is needed for me to display another set of details depending on which the first row in the table is. Any clue ?

Answer Source

You can use filters from javascript $filter('orderBy')(collection, expression, reverse, comparator). = $filter('orderBy')(vm.albums, 'data.title')[0]

This will sort albums by data.title and extract top row.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download