jacque wrote: ↑Sun Dec 04, 2022 10:04 pm
As long as we're throwing ideas around, this may help someone, someday. I create a list of 552 lines using the colornames. The script assigns metadata to each line, and then sorts it by the metadata. I first started out by creating a custom sort function but that took too long (1.5 seconds, vs 1.5 milliseconds by not touching the field.)
Jacque, brilliant and thank you for posting that. It was so similar in structure to what I was already doing that I was able to implement it quite quickly...
Code: Select all
constant kTag = "<p arrayKey=[[k]]>[[tText]]</p>" -- Jacque
repeat for each key k in gUserdefinedFolderArray
put gUserdefinedFolderArray[k] into tText -- the array content for key k
put merge(kTag) & cr after tList -- k and tText are merged into an html string (see constant kTag)
end repeat
set the htmlText of field "userDefinedBookmarkFolders" to sortText(tList)
function sortText pList -- Jacque
-- sorts a list of html strings by the embedded key value in each
set the itemDel to "="
sort pList numeric by item 2 of each
set the uOriginalList of this stack to pList
return pList
end sortText
It worked perfectly, did not require any kludgy "hide in column 2000" (as I think someone here described it
) and I even implemented your suggested reset by storing the sorted list in a custom property. All worked perfectly. However, since I've not worked with htmlText or merge (what an amazing command that is) I have a question.
As you may have noticed, I changed some of the text in the constant from "metadata" to "arrayKey" to make it more transparent what was being stored and it worked fine. I even experimented and changed it to "arrayKey and anything else I want" and it still worked fine. So I take it that when LC parses the htmlText it just ignores everything between <p and > and you can put whatever you want in there? Although important for us as we are using the k term to sort the array after delimiting on "="...
Code: Select all
sort pList numeric by item 2 of each
It was also invisibly fast on the table I was displaying (169 rows). Thanks again, I'm sure that technique could come in handy in other places as well.
Mark