13 Replies Latest reply on Jul 22, 2016 10:07 PM by RichardStuart_2

    Smart Sort List View

    G T

      Hello,

       

      I do not know if this is the appropriate area for this.

       

      I have uploaded a simple technique for sorting list views.

      It consists of 1 script with no dependencies.

      Sorts occur dynamically, each column restores it's last sort order and a default sort order can be set for each field type.

       

      I would appreciate it if anyone thinks it can be improved.

       

      Comments appreciated.

       

      Requires FMP 12.

       

      Thanks, Greg.

        • 1. Re: Smart Sort List View
          DavidJondreau

          At first blush, it looks very sharp!

          • 2. Re: Smart Sort List View
            Fred(CH)

            Yep. +1.

             

            As kind of improvement, i suggest you add the Code ( Get ( WindowsName ) ) as index to the variable (repetition number), in order to avoid bugs when multiple windows are open. I got this tip from David.

             

            Fore instance, as the repetition number, you could replace :

            Get ( LayoutNumber )

            by

            Code ( Get ( LayoutNumber ) & " | " & Get ( WindowsName ) )

            • 3. Re: Smart Sort List View
              rrrichie

              Looks very nice!  Simple and clean. 

               

              As far as portability I would add an error checker after the goto object.  That way if a object name drops of the radar it warns the developer.

              • 4. Re: Smart Sort List View
                G T

                Version 1.0.2 has been uploaded.

                 

                I have made the two changes recommended by Fred and rrritchie.

                The notes also reflect the changes and the names of those who helped.

                 

                Thank you,

                Greg

                • 5. Re: Smart Sort List View
                  G T

                  Fred(CH),

                   

                  I added your recommendation

                  That is a long repetition, however.

                   

                  Thanks,

                  Greg

                  • 6. Re: Smart Sort List View
                    G T

                    rrritchie,

                     

                    I added your recommendation as well.

                     

                    Thanks,

                    Greg

                    • 7. Re: Smart Sort List View
                      RichardStuart_2

                      Hi, Greg:

                       

                      Forgive my density but I'm having a little trouble understanding how the default sort order is determined.

                       

                      Say I have the following sort orders:

                      ID (A)

                      Name (D)

                      Street (A)

                      Time (D)

                      Date (A)

                      Phone (D)

                       

                      ...and I click on the Phone tab with Shift key depressed. That clears the sort orders and reverts them back to the default order, but I'm failing to understand how that's determined; on the face of it, it looks like ID (A) is the default field/sort order but referring to the line of code for Value on line 95:

                       

                          // These field types will default from A to Z.
                         $fieldType = "Text" ;
                         Case ( GetValue ( $list ; 1 ) = $fieldName & "A" ; "D" ; "A"
                         ) ;

                       

                         // Everything else defaults from High to Low.
                         GetValue ( $list ; 1 ) = $fieldName & "D" ; "A" ; "D"

                          ) ;

                       

                      The ID field is a Number field and sorts ascending. Also, how is it denoted as the "primary" field (1) for the sort? Your script works great, just that I don't fully understand how ti works. Could you please educate me?

                       

                      Thanks,

                      Rich

                      • 8. Re: Smart Sort List View
                        G T

                        Richard,

                         

                        Hope I can help.

                         

                        on the face of it, it looks like ID (A) is the default field/sort order but referring to the line of code for Value on line 95:

                         

                        // These field types will default from A to Z.
                        $fieldType = "Text" ;
                        Case ( GetValue ( $list ; 1 ) = $fieldName & "A" ; "D" ; "A"
                        ) ;

                         

                        // Everything else defaults from High to Low.
                        GetValue ( $list ; 1 ) = $fieldName & "D" ; "A" ; "D"

                            ) ;

                         

                        This above calculation comes into play when either condition is met:

                        You have just sorted on the same field, in which case, the sort order is simply reversed (regardless of field type).

                        The field is not contained in $list, in which case, GetValue ( $list ; 1 ) = $fieldName & "XX" is false. Therefore, the field type will determine the default sort order as text fields will default to (A) and all others will default to (D).

                         

                        ID field is defined as a number field and will default to (D) descending if it is not contained in $list. Any non-text field that is sorted when $list is empty or is not contained in $list will default to (D) descending as per the rules above.

                         

                        The ID field is a Number field and sorts ascending.

                         

                        I am not seeing this behavior. When I sort on the ID field ( field type = "number" ) under these conditions, it will sort (D) descending as will all fields other than field type = "text". It will only sort (A) ascending if it was previously sorted (D) descending.

                         

                        how is it denoted as the "primary" field (1) for the sort?

                         

                        As I understand your question, there is no primary field for any of the sorts as Filemaker can only sort on the (1) field named in the parameter with this technique. $list only maintains a history of sorts, which can in turn, be used to determine the sort order of that one field.

                         

                        Let me know If this helps.

                         

                        Greg

                        • 9. Re: Smart Sort List View
                          G T

                          Richard,

                           

                          I have clarified the calculation a bit and made a few changes,

                           

                          Version number is now v.1.0.3.

                           

                          v1.0.3 - 08/30/15

                          Clarified comments in sort order calculation.

                          Changed Error Code display. It is now more portable for use in other scripts.

                          Simplified instructions and notes with a more consistent display between FM application versions.

                          MIT License added.

                           

                          https://www.adrive.com/public/HYBuFd/Smart%20Sort%20List%20View.fmp12%20v1.0.3.zip

                           

                          I hope this eliminates any confusion.

                           

                          Greg

                          • 10. Re: Smart Sort List View
                            RichardStuart_2

                            It does, and thank you _very_ much for addressing my post so quickly.

                             

                            Cheers,

                            Rich

                            • 11. Re: Smart Sort List View
                              Vincent_L

                              I've to say Richard, that this is BRILLANT and AWESOME

                              Many thanks for sharing this

                              • 12. Re: Smart Sort List View
                                G T

                                I thought I'd upload the last version (v1.04) of Smart Sort List View as v1.03 is no longer available for download.

                                 

                                https://community.filemaker.com/servlet/JiveServlet/download/587495-77997/Smart%20Sort%20List%20View.fmp12.zip

                                 

                                There are only minor differences.

                                 

                                v1.0.4 - 10/23/15

                                Added If statement to prevent $activeField from being set with a global field.

                                 

                                Greg

                                • 13. Re: Smart Sort List View
                                  RichardStuart_2

                                  Thanks for the update!

                                   

                                  Cheers,

                                  Rich