Closed bvahdat closed 7 years ago
you can use a getter to return the computed property you want to sort with
controller.js
//..
$scope.getters = {
computed(row){
return row.firstName + row.lastname; //(stoopid example but you get it :) )
}
}
//
<th st-sort="getters.computed"> ... </th>
@lorenzofox3 sorry for getting back too late on this, too much running right now on my side. Your example is actually what the documentation is suggesting, which is fine. But the behaviour is not exactly what I'm after, as because state changes after each click are always in this order ascending
=> descending
=> primary order
. Given my example with foo
and bar
properties above, this is what going on:
Good case:
First click on first name
label => Sorts firstName
ascending
Second click on first name
label => Sorts firstName
descending
Third click on first name
label => Primary sort order by firstName
First click on last name
label => Sorts lastName
ascending
Second click on last name
label => Sorts lastName
descending
Third click on last name
label => Primary sort order by lastName
Bad case:
First click on first name
label => Sorts firstName
ascending
First click on last name
label => Sorts lastName
descending (oops, my expectation would be ascending here!)
As because the state transition is always fixed given as ascending
=> descending
=> primary order
, it doesn't matter which property I return from my function as the state transition order is always fixed.
I hope this makes it clear about what the issue is, otherwise I could provide a simple example on Codepen if you want me to do so.
Not sure to fully understand. But an idea would be to create your own directive which keep track of the sorting state and call the table api directly with the sequence you wish. You can have a look at the stSort directive source code if you need an example
Using
angularjs 1.5.9
assume two given properties such asfoo
andbar
being bound to a single column. Is there any way to instructst-sort
to either sort according to thefoo
orbar
values. That's something along the following lines: