Ask your support contact to add you to list of requestors for Bz3491
https://4js.com/en/support/issue/?id=3491As the issue notes, the difficulty is handling the case if you sort whilst in a dialog.
For the sort problem, in the past I had a pre-processor directive
&define arraysort(p_arr,p_sort,p_temp,i1,i2) FOR i1 = 1 TO p_arr.getLength() \
FOR i2 = (i1+1) TO p_arr.getLength() \
IF p_arr[i1].p_sort > p_arr[i2].p_sort THEN \
LET p_temp.* = p_arr[i2].* \
LET p_arr[i2].* = p_arr[i1].* \
LET p_arr[i1].* = p_temp.* \
END IF \
END FOR \
END FOR
and then I could code ...
arraysort(array-variable,sort-column, temp-variable, idx1, idx2)
... only hassle I recall was having to have the temp-variable and two variables for indices defined.
From 2.50 on, I would investigate writing a function using the JSONObject and JSONArray methods. A quick test suggests something similar to ...
FUNCTION json_array_sort(ja, sort_col)
DEFINE ja util.JSONArray
DEFINE jo1, jo2,t util.JsonObject
DEFINE sort_col STRING
DEFINE i,j INTEGER
DEFINE type STRING
FOR i = 1 TO ja.getLength()
FOR j = (i+1) TO ja.getLength()
LET jo1 = ja.get(i)
LET jo2 = ja.get(j)
IF jo1.get(sort_col) > jo2.get(sort_col) THEN
LET t = jo2
CALL ja.put(i,jo2)
CALL ja.put(j,jo1)
END IF
END FOR
END FOR
END FUNCTION
... could be called by ...
DEFINE ja util.JSONArray
LET ja = util.JSONArray.fromFGL(array-variable)
CALL json_array_sort(ja,sort-column)
CALL ja.toFGL(array-variable)
... there is probably room for improvement but that is a starting point.
It builds on a technique I've used before where my copy entire array to clipboard function used base.Typeinfo so that the function took as input a DomDocument, not an array, and hence could be called by any array e.g.
CALL copy_entire_array_to_clipboard(base.TypeInfo(array-variable))
Hope that helps,
Reuben