Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

One script for sorting ascending/descending

Featured Replies

On one list layout, I have a 5 fields. It is possible created a just one script for sorting ascending/descending for all 5 fields?

Use Getfield() function. It will help you to do whate you want.

Or use script parameters to branch in one sort script.

  • Author

I think that catch is in script parameter, but how to add a script parameter in sort step, when there isn't a calculation? In sort step You must specify a field for sorting.

Use a global for remembering the last sort, and a script parameter to know what the selected sort is on:


If [ Get(ScriptParameter) = "Name" ]

  If [ gLastSort = "Name Ascending" ]

    Sort [ Restore ; by Name (Decending) ]

    Set Field [ gLastSort ; "Name Decending" ]

  Else

    Sort [ Restore ; by Name (Ascending) ]

    Set Field [ gLastSort ; "Name Ascending" ]

  End If

Else If [ Get(ScriptParameter) = "Date" ]

  If [ gLastSort = "Date Ascending" ]

    Sort [ Restore ; by Date (Decending) ]

...

  • Author

[color:"green"] Use a global for remembering the last sort

Yes, that is right.

[color:"green"]

If [ Get(ScriptParameter) = "Name" ]

  If [ gLastSort = "Name Ascending" ]

    Sort [ Restore ; by Name (Decending) ]

    Set Field [ gLastSort ; "Name Decending" ]

  Else

    Sort [ Restore ; by Name (Ascending) ]

    Set Field [ gLastSort ; "Name Ascending" ]

  End If

Else If [ Get(ScriptParameter) = "Date" ]

  If [ gLastSort = "Date Ascending" ]

    Sort [ Restore ; by Date (Decending) ]

...

[/color] 

That solution is OK for one layout. But my application contain almost 50 layouts, and will be very useful to create a dynamic system, one dynamic script for all possibly fields.

Something like.... that You shouldn't precise what field is sorting (e.g. "by Date")in script step:

Sort [ Restore ; by Date (Decending) ]

If can, on some way script parameter do that.... On that way created script can be useful in every future application. Dancing-Chilli.gif

...

In that case, look into doing it with GetField(). I posted a sample of this a couple months back. In was in a thread about 'dynamic reports' or 'dynamic portals'.

Hi,

Yes, GetField is the way to go as a start, but could get a bit more complex if the fields format could vary, from Time, Date, Number ot Text.

I've posted a demo in the Samples Forums to account for these cases.

The demo use a portal but can be used with lists as well.

  • Author

In that case, look into doing it with GetField(). I posted a sample of this a couple months back. In was in a thread about 'dynamic reports' or 'dynamic portals'.

Sorry but I can't find your posted sample. frown.gif Can You give me a link, please?

  • Author

Hi,

Yes, GetField is the way to go as a start, but could get a bit more complex if the fields format could vary, from Time, Date, Number ot Text.

I've posted a demo in the Samples Forums to account for these cases.

The demo use a portal but can be used with lists as well.

Thanx Ugo,

I'll get back later with my impressions. First I must read Your calc. field very patiently; it's complicated for my skill of filemaker. I hope that will help me.

  • Author

Thanx man, You are VERY fast. :-)

  • Author

Hi again,

Thanks everybody for help!

I attached my solution for dynamic sort here, and on post in Sample files too.

My solution required that every layout have a three extra fields ( text, number and date). They are a temporary fields in which values are copied from desired sort column fields.

Now, I have another question. Loop is very slow for thousands records; how can be faster? UGO sent a file RandomCreation few days ago, but unfortunately I can understand it. frown.gif Can You please, give some extra instruction for using Your faster loop solution?

TIA

dynamic_sort.zip

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.