Dynamic Portal Sorts

n filemaker we can’t execute sort functionality directly on a list of records on a portal as the portal sort records is defined in the portal definition. To handle sorting records dynamically on a portal we can follow the below steps.

1.Create one global field(let’s say gSortKey) in the table on which the portal is based.

2.If the portal only displays text fields then add one unstored calculation field(calcFieldContentText which returns text value). If portal contains both text, date and numeric fields then add 2 unstored calculation fields(calcFieldContentText which returns text value andcalcFieldContentInt which returns number value).For the fields calculation will be

calcFieldContentInt = Case( not PatternCount(FieldType("Filename";gSortKey) ; "Text");GetField(gSortKey);"")
 
calcFieldContentText = Case( PatternCount(FieldType("Filename";gSortKey) ; "Text");GetField(gSortKey);"")
 
3.On the portal setup, select sort portal records and add calcFieldContentInt and calcFieldContentText.

4. Add a script having following steps

    Set Field[gSortKey,Get(ScriptParameter)]

    Refresh Window[Flush cached join result]

Note that the script parameter will be the field name on which you want to sort the portal records.

5.Finally add the script to the portal header titles and pass the fieldnames as per the titles.

That’s it..your portal sorting is ready.

The above one is meant for one way portal sort(Ascending or Descending). But to have the portal sort in both direction we need to add some more stuff to the above technique.

1.Add one global field (let’s say gSortType) to keep the sorting type.

2.Add 2 more calculation fields calcFieldContentIntDesc andcalcFieldContentTextDesc .

calcFieldContentIntDesc = if(gSortType = "Desc";Case( not PatternCount(FieldType("Filename";gSortKey) ; "Text");GetField(gSortKey);"");"")
 
calcFieldContentTextDesc = if(gSortType = "Desc";Case( PatternCount(FieldType("Filename";gSortKey) ; "Text");GetField(gSortKey);"");"")

3.Modify the previous calculation fields a bit.

calcFieldContentInt = if(gSortType ≠ "Desc";Case( not PatternCount(FieldType("Filename";gSortKey) ; "Text");GetField(gSortKey);"");"")
 
calcFieldContentText = if(gSortType ≠ "Desc";Case( PatternCount(FieldType("Filename";gSortKey) ; "Text");GetField(gSortKey);"");"")

4.Modify the sort script a bit. The new sort script will contain the following steps.

#Check the sort type

   If [ Table::_g_SortKey = Get ( ScriptParameter ) ]

       If [ Table::_g_SortType = "Asc" ]

           Set Field [ Table::_g_SortType; "Desc" ]

       Else

           Set Field [ Table::_g_SortType; "Asc" ]

       End If

   Else

       Set Field [ Table::_g_SortType; "Asc" ]

   End If

       #

   Set Field [ Table::gSortKey,Get(ScriptParameter) ]

   Refresh Window[Flush cached join result]

Now your Portal sort is ready. On clicking the title ,It will sort the records asceding format, then on next click it will sort descending format.

150 150 Burnignorance | Where Minds Meet And Sparks Fly!