3 Replies Latest reply on Jan 18, 2014 3:23 AM by user28097

    How to determine current sort order

    user28097

      I see the Get ( SortState ) function that returns whether the current table is sorted or not. Is there a way to determine the current sort order?

       

      The idea is that I would like to allow the user to click a column header in a list view and sort the list based on that field. This is easy and is working, but I would also like to give a visual cue (a little triangle on that column as is common) as to which column is the current sort in the column header. I can do this by setting a variable each time a column header is clicked, but was hoping there is a way to programmatically determine the sort order.

        • 1. Re: How to determine current sort order
          taylorsharpe

          You can always use a global variable to set whenever you're scripting the sort that lets you know how you last sorted. 

          • 2. Re: How to determine current sort order
            mikebeargie

            Taylor's method is what most of us use.

             

            To answer your question, no, there is no function that returns what order something is sorted on. You have to keep track of it yourself.

             

            Something scripted like:

             

            -Set Variable $$SortField = "the field you're sorting on"

            -Set Variable $$SortDirection = "ASC/DESC"

            -Sort Records.

             

            Then you could either do some sort of conditional formatting, or FM13's new "Hide Object when" feature to show and hide buttons accordingly.

             

            IE in FM13, if I have blue arrows up and down, and red arrows up or down, and a table::name field. I could apply this to those 4 buttons:

             

            Blue up = Hide object when - $$SortField = table::name

            Blue down = Hide object when $$SortField = table::name

            Red up = Hide object when - $$SortField =/= table::name and $$SortField > "" and $$SortDirection = "DESC"

            Red down = Hide object when $$SortField =/= table::name and $$SortField > "" and $$SortDirection = "ASC"

             

            This would give me blue up and down arrows when it is not sorted by that field, and then a red arrow to indicate when it IS sorted by that field, and which direction. You can always make this more complex by adding in the ability to add/remove fields to your sort order as well.

             

            Good Luck!

            • 3. Re: How to determine current sort order
              user28097

              Thanks for the detailed reply. This is essentially what I did.