satya satya - 2 years ago 155
AngularJS Question

How to sort table as per the number value using Angular.js

I need one help.I need to sort the table row value as per one column which contains some number type value using Angular.js. I am explaining my code below.

<tr ng-repeat="c in clickSummary">

obejct is containing some array of data.This above table output is displaying like below.

sl no name page hit map hit gallery hit web hit total

1 aaa 1 1 0 1 3

2 bbb 2 2 1 0 5

3 ccc 1 2 3 0 6

4 ddd 1 3 0 0 4

5 eee 2 4 1 2 9

Here i need to sort as per
column value means it should come in descending order(
).Please help me.

Answer Source

By orderBy filter:

<tr ng-repeat="c in clickSummary | orderBy:['-total','+rest_name'] ">

Here is a live demo

Angular orderBy Docs:

Orders a specified array by the expression predicate. It is ordered alphabetically for strings and numerically for numbers. Note: if you notice numbers are not being sorted as expected, make sure they are actually being saved as numbers and not strings. Array-like values (e.g. NodeLists, jQuery objects, TypedArrays, Strings, etc) are also supported.

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