Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 3578 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

:hmm: Newbie alert!

 

Sorry for the confusing title but but what else could I use?

 

I want to use the row header text in a list layout to run a sort script, however as I can only add one script to each header I have added two arrows near each row header, one runs a script to organise the layout by that row in ascending order, the other in descending order.

 

Thing is it look unsightly and I'd much rather do away with the arrows and be able to attach a script to the row header itself that on first press it sorts the layout by that row in ascending order, then if that isn't what I want... on the second press it sorts the layout by that row in descending order and so on and so on...

 

If you think any answer will be too much for a newbie just say so and I'll stick with my unsightly arrows... but if there is a chance I might grasp it, feel free to let rip and give me some directions.

 

I'm well aware I can make my arrow design much better, I've only just thrown it together to see if it will work, but I'd much rather get rid of the arrows altogether, here's a image-clip.

 

Snapshot

 

Ugly I know but as I have already hinted at, once I get the whole thing working as I want then I'll be looking to visual stuff. 

 

Appreciate any advice, Karlos.

 

Posted

attach a script to the button that passes a sort order and a field name parameter into the script that will perform the sort.

the param can be anything that indicates asc or desc order is what you want to happen as a result of the button click and the fieldname you want to sort on.

Look into multi parameter passing strategies.

 

Button parameter pseudocode:

if global variable = "asc" then pass in "desc"

If global variable = "'desc" then pass in "asc"

 

 

script pseudocode...

get field name parameter

get order parameter

Evaluate field name

evaluate order parameter

If fieldname = "a" then

           if sort order = asc sort field "a" asc

                set global variable to "asc"

           if sort order = desc sort field "a" desc

                set global variable to "desc"

Repeat tilll all fields you want to sort on are factored in.

 

 

Hopefullly you get the idea.

Youll have to plan what happens when layout is an unsorted state and a bunch of other situations in order for this method to work without fail.

Posted

script pseudocode...

get field name parameter

get order parameter

EvAluate field name

evaluate order parameter

If fieldname = "a" then

           if sort order = asc sort field "a" asc

           if sort order = desc sort field "a" desc

Repeat tilll all fields you want to sort on are factored in.

 

I am not exactly a beginner (or at least I'd like to think so) - and I have no idea what you're suggesting here.

 

 

 

on first press it sorts the layout by that row in ascending order, then if that isn't what I want... on the second press it sorts the layout by that row in descending order

 

For this to work, you must keep a memory of the previously pressed button (or buttons) somewhere, e.g. in a global variable. IIUC, you want the records to be sorted only by one column (the last one pressed) - not a combination of columns?

Posted

For this to work, you must keep a memory of the previously pressed button (or buttons) somewhere, e.g. in a global variable. IIUC, you want the records to be sorted only by one column (the last one pressed) - not a combination of columns?

 

One column will be Dandy... [more risks a nose bleed]

I'm just watching a Youtube video to try to get my head around storing global data to pass to scripts... Passing Data Between FileMaker Scripts in the hope I can understand this concept. 

 

Slightly confused... Karlos.

Posted

Sorry for the crappy description. Heres what i meant.

 

Their is no error checking in the script.

 

It only sorts one field.

 

Their are other ways to do this.

 

Kris


Works better with an actual attachment.

 

 

Lots of possibilities to extend this

sort.fmp12.zip

Posted

It's not that complicated, but you need to keep in mind two things that work against you in this scenario:

 

1. There is no way to tell Filemaker to sort records by [pass a fieldname here]; the sort order is "baked" into the Sort Records script step;

 

2. Filemaker will only tell you if records are currently sorted or not (or somewhere in-between) - not in what order are they sorted.

 

This means you need to have some kind of a "code name" for each column (which could be the same as the actual field name, but it's really just a string) and use this as follows (roughly):

 

First, pass the code as the parameter to the sorting script. Then have the script compare the script parameter with a global $$sortColumn variable: if they are the same, toggle the $$sortOrder variable from ascending to descending, or vice versa; if they are different, set the $$sortColumn variable to the parameter, and the $$sortOrder variable to ascending.

 

Now you have your variables set up for the actual sort that needs to be performed, and you need to go through a series of If[] and Else If[] steps to select the corresponding Sort Records[] step (there will be two such steps stored for each field you may want to sort by, one ascending and one descending.)

 

--

Note that the actual sort order may include more that one field; for example the user may click on "Name", but the script will sort by LastName and by First Name.

Posted

1. There is no way to tell Filemaker to sort records by [pass a fieldname here];

 

This is an opportunity for improvement in FileMaker. It would be nice to be able to write a completely abstracted sort script.

Posted

Sorry for the crappy description. Heres what i meant.

 

Their is no error checking in the script.

 

It only sorts one field.

 

Their are other ways to do this.

 

Kris

Works better with an actual attachment.

 

 

Lots of possibilities to extend this

 

Thanks Kris.

I'm wiped-out at present, relaxing listening to a podcast but will take a look at your file tomorrow.

 

Thanks again, Karlos.

It's not that complicated, but you need to keep in mind two things that work against you in this scenario:

 

1. There is no way to tell Filemaker to sort records by [pass a fieldname here]; the sort order is "baked" into the Sort Records script step;

 

2. Filemaker will only tell you if records are currently sorted or not (or somewhere in-between) - not in what order are they sorted.

 

This means you need to have some kind of a "code name" for each column (which could be the same as the actual field name, but it's really just a string) and use this as follows (roughly):

 

First, pass the code as the parameter to the sorting script. Then have the script compare the script parameter with a global $$sortColumn variable: if they are the same, toggle the $$sortOrder variable from ascending to descending, or vice versa; if they are different, set the $$sortColumn variable to the parameter, and the $$sortOrder variable to ascending.

 

Now you have your variables set up for the actual sort that needs to be performed, and you need to go through a series of If[] and Else If[] steps to select the corresponding Sort Records[] step (there will be two such steps stored for each field you may want to sort by, one ascending and one descending.)

 

--

Note that the actual sort order may include more that one field; for example the user may click on "Name", but the script will sort by LastName and by First Name.

 

Thanks comment, will keep your instructions in mind in the morning.

Appreciated, Karlos.

Posted

Sorry for the crappy description. Heres what i meant.

 

Their is no error checking in the script.

 

It only sorts one field.

 

Their are other ways to do this.

 

Kris

Works better with an actual attachment.

 

 

Lots of possibilities to extend this

 

Hi Kris.

 

I thought I just take a quick look at your file before I called it a night, but Filemaker couldn't open it. It has an extention on it I dont recognise [.ink] and my Mac thinks it should be opened on a Windows machine.

 

I'm running FileMaker Pro 13 on a Mac, is there something that should be done when passing a file between PC and Macs? Or is it because you are running Filemaker 13 Advanced? [if you are]. My understanding was that files were transferable betwween OSX and Windows, am I correct?

 

Your files shows as "sort.fmp12.lnk" but I was expecting 'sort.fmp12'

I changed it to 'sort.fmp12' but it said something about the "translator for this format could not be found or initialized"

 

Karlos.

Posted

.lnk is a Windows shortcut (analogous to a Mac alias).

 

So he has accidentally sent me a short-cut to his file on his PC, instead of the actual file itself? The file is only 16kb so that would make sense.

 

Cheers, Karlos.

Posted

So he has accidentally sent me a short-cut to his file on his PC, instead of the actual file itself? The file is only 16kb so that would make sense.

 

Cheers, Karlos.

I posted a mistake the first time.. sorry

Oops...

sort.fmp12.zip

Posted

I posted a mistake the first time.. sorry

Oops...

 

Hi Kris.

Just got in and downloaded your file, works great and I will look to integrate it into my file tomorrow.

 

Thanks again, is appreciated... Karlos. 

This topic is 3578 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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