3 Replies Latest reply on Aug 3, 2014 6:55 AM by philmodjunk

    Want to create drop-down list that allows me to sort records by different criteria

    HugoW

      Title

      Want to create drop-down list that allows me to sort records by different criteria

      Post

           All I want to do is create a drop-down field that, when tapped, allows the user to sort a list of records by a series of possible selections.

           For example, when I tap on the field, I want it to give me the following options:

            

           First Name

           Last Name

           City

           State

            

           I want to be able to tap on "First Name" and have the records sorted by--you guessed it--first name. How on earth do I do this?

            

           Also, when the user sorts by first name or last name, I would like a "label" to appear above each group of names showing the letter of the alphabet. All A names will have an "A" label above them, etc. 


           Does this make sense?

            

        • 1. Re: Want to create drop-down list that allows me to sort records by different criteria
          TKnTexas

               Good question.  I was wondering this myself.

          • 2. Re: Want to create drop-down list that allows me to sort records by different criteria
            raybaudi
                 The script is quite simple:
                  
                 Script name: Custom Sort
                  
            Go to Object [ Object Name: Get ( ScriptParameter ) ]
            Sort Records by Field [ no field name here ; Ascending ]
            Exit Script [ Result: 0 ]
                  
                 but you'll have to:
            1) give an object name to all the fields that you need to sort. The name must be the same as the field's name.
            2) create a custom value list with the names of those fields.
            3) create a global text field ( name it "sort by" ) with control style as Drop-down list using values from the custom value list.
            4) apply to the global field an OnObjectExit trigger that runs the above script with YourTable::sort by as the script parameter.
                  
                 Note that the script is portable because it is indipendent from any field's name and you could have another one with "Descending" option.
            • 3. Re: Want to create drop-down list that allows me to sort records by different criteria
              philmodjunk

                   I like the elegance of Raybaudi's script, but it doesn't produce names grouped under a first letter "index" sub heading as requested. That will take treating name sorts as a "special case" where you sort on two fields and that can't be done with Sort Record by Field. Also, if you are going to be selecting values in a global field, you don't need the script parameter as you can use the values specified for the global field's drop down as your object names and then the first step can be:

                   Go to Object [YourTable::TheGlobalFieldHere]

                   But that's a "minor quibble". The key detail is how to get those index sub heads to appear.

                   Modify Raybaudi's basic idea as follows:

                   If [YourTable::TheGlobalFieldHere = "Last Name" ]
                      Sort Records [Restore ; No Dialog ]
                   Else IF [ YourTable::TheGlobalFieldHere = "First Name" ]
                       Sort Records [Restore ; No Dialog ]
                   Else
                     /* Put raybaudi's script here */
                   End IF

                   To get your indexing sub heads, you'll need to add two fields and two sub summary layout parts to your layout. Add this calculation field cLastNameFirstLetter, defined as: Left ( LastName ; 1 ). Add cFirstNameFirstLetter defined as: Left ( FirstName ; 1 ).

                   Now add two sub summary layout parts, Set up one as "when sorted by cLastNameFirstLetter and the other as cFirstNameFirstLetter. Put these calculation fields in their respective sub summary layout parts.

                   Next, for the first Sort Records step shown above, sort on two fields, specify cLastNameFirstLetter as the first field and LastName as the second. Do the same for the second sort Records step, but specify cFirstNameFirstLetter and FirstName as the two sort fields.

                   Sub Summary layout parts are only visible when their specified sort fields are included in the sort order so they will only appear when you select the appropriate "name" field as the field on which you want to sort records.