Jump to content
Salesforce and other SMB Solutions are coming soon. ×

script for sorting column


Recommended Posts


i want to know how to write script for this situation...................

A click on a

columnheadline, will sort this specific headline. Another click on the same column will turn the

order around for rising to falling and again from falling to rising.



Link to comment
Share on other sites

Don't need a script at all, actually.


Set view to Table View. In Layout Setup --> Views --> Table Views --> Properties, activate the option "Sort data when selecting column".


It automatically does the "reverse sort order when you click a second time" thingie.


If for some reason you do not wish to deploy Table View, I can outline a script technique for you, but tell me how many columns we're talking about here before we go there — the method I'd use for 3-4 columns is different from what I'd use for 40-70 columns.

Link to comment
Share on other sites

actually i dont't want to deploy Table View

and i used 8 column for sorting


I should have also asked you how many records you usually need to sort, and whether your fields are all indexed. I'm going to assume you can tolerate a somewhat sluggish sort due to an unindexed field being involved.


OK. For eight columns' worth I'd do it this way:


Where your fields from left to right are named Field A, Field B, Field C, Field D, Field E, Field F, Field, G, and Field H;


define two global text fields, g.SortField and g.SortDir;


define one calc field — result type text UNLESS all of fields A-H are number fields, date fields, time fields, timestamp fields etc, in which case make this field of that type; instructions will assume type text though...formula is


GetField (g.SortField)


now create this script:


If [YourTable::g.SortField ≠ Get(ScriptParameter)]

.. Set Field [YourTable::g.SortField, Get(ScriptParameter)]

.. Set Field [YourTable::g.SortDir, "ascending"]

.. Sort [no dialog, YourTable::NewCalcField, ascending]

Else If [g.SortDir = "descending"]

.. Set Field [YourTable::g.SortDir, "descending"]

.. Sort [no dialog, YourTable::NewCalcField, descending]


.. Set Field [YourTable::g.SortDir, "ascending"]

.. Sort [no dialog, YourTable::NewCalcField, ascending]

End If



Put button at top of each column in the Header part. Same script for each button, but put the field name as the script parameter, e.g., "Field A", "Field B", etc.



EDIT 5/2/08: For fields where the original field type is date or time, you have to do some extra work in the field def of NewCalcField. GetField (g.SortField) where g.SortField contains "Date Created" for example, is going to reconcile to something like "3/12/2008" in NewCalcField but NewCalcField, being a calc of type "text" will not see "12/7/2007" as coming before that, etc... so you have to figure out which fields need to be coerced and handle them explicity in a Case statement, turning their values into text strings that will sort properly. e.g. —


Case (g.SortField = "Date Created", Year(Date Created)&Right ("0"&Month(Date Created), 2) & Right ("0"& Day(Date Created), 2); GetField (g.SortField) )

Link to comment
Share on other sites

  • 3 months later...
  • Gold Members

There's a related thread that I just replied to. It's Change Header Label in Tables (I wish FM Cafe would add identifiers to these threads).


Anyway, is this script solution the only way to get rid of unsightly column headings while retaining the ability to sort by column. Seems very radical. Can't the FM engineers give us an option to hide/edit table headers so our users can happily click a column header to sort?????

Link to comment
Share on other sites

  • Create New...

Important Information

Terms of Use