| 32 | |
| 33 | //view --> table state |
| 34 | function sort () { |
| 35 | if (descendingFirst) { |
| 36 | index = index === 0 ? 2 : index - 1; |
| 37 | } else { |
| 38 | index++; |
| 39 | } |
| 40 | |
| 41 | var func; |
| 42 | predicate = ng.isFunction(getter(scope)) || ng.isArray(getter(scope)) ? getter(scope) : attr.stSort; |
| 43 | if (index % 3 === 0 && !!skipNatural !== true) { |
| 44 | //manual reset |
| 45 | index = 0; |
| 46 | ctrl.tableState().sort = {}; |
| 47 | ctrl.tableState().pagination.start = 0; |
| 48 | func = ctrl.pipe.bind(ctrl); |
| 49 | } else { |
| 50 | func = ctrl.sortBy.bind(ctrl, predicate, index % 2 === 0); |
| 51 | } |
| 52 | if (promise !== null) { |
| 53 | $timeout.cancel(promise); |
| 54 | } |
| 55 | if (throttle < 0) { |
| 56 | func(); |
| 57 | } else { |
| 58 | promise = $timeout(function(){ |
| 59 | func(); |
| 60 | }, throttle); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | element.bind('click', function sortClick () { |
| 65 | if (predicate) { |