Togles sort order for a given column in current layout, with one click alternate sort order
Warning: this is pure experimentation and, as usual with FileMaker, a really ridiculous-complex workaround for a simple basic functionality. But, you know what…
# togles sort order for a given column in current layout
# created by air.fsans@gmail.com 2021
# dependencies:
(CF) Split() https://gist.github.com/2362de406f7935d9c9e56ed44aa10db0
(PLUGIN) BaseElements +4.1
# expected parameter
# { field : fablename::fieldname }
Set Variable [ $PARAMS; Value:Get(ScriptParameter) ]
Set Variable [ $TABLE; Value:GetValue ( Split ( $PARAMS ; "::" ) ; 1 ) ]
Set Variable [ $FIELD; Value:GetValue ( Split ( $PARAMS ; "::" ) ; 2 ) ]
Set Variable [ $SORT_MODE ]
If [ Get(SortState)<>0 ]
#some sorting present... get it generating a fm snapshot link file (let me know about some better hack)
Set Variable [ $PATH; Value:Get(TemporaryPath) & Get(UUID) & ".fmpsl" ]
Save Records as Snapshot Link [ File Name: “$PATH”; Create folders:No; Records being browsed ]
Set Variable [ $FILE ]
Set Variable [ $FILE_EXISTS ]
Set Variable [ $SIZE ]
Set Variable [ $FILE_ID ]
Set Variable [ $DATA ]
Get File Exists [ “$PATH” ; Target: $FILE_EXISTS ]
If [ $FILE_EXISTS ]
Open Data File [ “$PATH” ; Target: $FILE_ID ]
Get File Size [ “$PATH” ; Target: $SIZE ]
Read from Data File [ File ID: $FILE_ID ; Amount (bytes): $SIZE ; Target: $DATA ; Read as: UTF-8 ] Close Data File [ File ID: $FILE_ID ]
Else
Show Custom Dialog [
Title: "ERROR";
Message: "File " & $PATH & " doesn't exists";
Default Button: “OK”,
Commit: “Yes” ]
Exit Script [ Result: 0 ]
End If
Set Variable [
$SORT_ORDER;
Value:BE_XPath( $$DATA ; "//Sort[ (PrimaryField/Field/@name=" & Quote($FIELD) & ") and (PrimaryField/Field/@table=" & Quote($TABLE) & ") ]/@type" )
# temporary debug
Set Variable [ $$DATA; Value:$DATA ]
# check if current clicked column header (field name) is in the sort list
Set Variable [
$TARGET_SORTING;
Value: Case( $SORT_ORDER = "Ascending"; "Descending" ; "Ascending") ]
Sort Records [ ]
End If
**ToDos**
- Multicolumn sorting
- Multicolumn & reverse mixin
- Rest