Can I reverse the sort icons?

Can I reverse the sort icons?

dharknessdharkness Posts: 8Questions: 0Answers: 0
edited January 2010 in General
I have a column (Age) that sorts on a hidden column (Created Date). Since one column is the inverse of the other, when sorted the displayed values are opposite the arrow (up means descending). Is there a way to reverse the arrows for this column?

Note that I know how to solve this programmatically and don't need a workaround. I could add a second hidden column (I need to keep the hidden Created Date column for another column's sorting) to store the age as a number as opposed to text (the reason I need the hidden column in the first place). I'm hoping there's a simpler solution that doesn't require loading up more data into the table. Thanks!

Replies

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    You could just add another class to the TH element for when you want to reverse the sorting icon, and have your CSS selector take account of that. If that class is there then 'reverse' the icons, if it is not, then leave them as is. How does that sound?

    Allan
  • dharknessdharkness Posts: 8Questions: 0Answers: 0
    edited January 2010
    Thanks, is this what you had in mind?

    * On the I added a class.
    [code]
    Age
    [/code]
    * In my CSS I added two selectors to reverse the icons used.
    [code]
    th[class~=reverse].sorting_asc {
    background:transparent url(images/sort_desc.png) no-repeat scroll right center;
    }
    th[class~=reverse].sorting_desc {
    background:transparent url(images/sort_asc.png) no-repeat scroll right center;
    }
    [/code]
    That's certainly easy enough to do. I still think adding a new
    [code]
    'bReverseSortIcons': boolean
    [/code]
    parameter to aoColumns to do the above automatically would be handy. Maybe even
    [code]
    'bReverseSort': boolean
    [/code]
    as shorthand for
    [code]
    'asSorting': ['desc', 'asc']
    [/code]
    but I also understand the value of a slim API. :)
  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    Hi dharkness,

    Thanks for the details. As you note, I think for the sake of keeping the API as basic as possible, I'm inclined not to add a new parameter such as bReverseSort which would effectively be doing the same thing as asSorting. I can see the advantage of it, since it increases accessibility of this particular option, and if it comes up as a request a few more times I might look at adding it. However, for the moment I'll leave it as it is. Hopefully anyone who wants to do this reserve sorting will have enough knowledge to use asSorting as well :-)

    Regards,
    Allan
This discussion has been closed.