Sort on two sortTypes

Jerry Jensen jerry at jhjensen.com
Sat Apr 8 14:32:27 EDT 2017


Bernd’s modTableField will let you do a custom sort. A sort function using something like your example:
> by (item 3 of each & item 2 of each)
should do the trick. It uses LC’s sort container function so the dictionary does apply.
On the other hand, if you sort by one item at a time, sort by the least significant item first, as in sort by the time item and then by the day item.
.Jerry

> On Apr 8, 2017, at 10:45 AM, Randy Hengst via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Hi All,
> 
> I’m working an app to facilitate the development of student class schedules.
> 
> Right now there are three items for each course that I’d like to sort in various ways: CourseName, Time, Days. The information is placed in that order in a field for display.
> 
> It’s easy to sort on any one of the items. For example….
> sort lines of field "FIRSTyear_FALL" by item 1 of each
> 
> sort lines of field "FIRSTyear_FALL" dateTime by item 2 of each
> 
> sort lines of field "FIRSTyear_FALL" by item 3 of each
> 
> 
> But I can’t figure out how to sort first on item 3, Days and then by item 2, Time. My goal is sort by matching Days and then by time in ascending order. The courses meeting on the same day would be grouped together by time earliest to latest. A sort does take place, but it’s text. I’ve not figured out how/where to place the dateTime sortType when combining a sort on item 3 and item 2. 
> 
> Here’s the basic line of script… where does “dateTime” go? I’ve tried placing it in all the points of the line that I can think of….
> sort lines of field "FIRSTyear_FALL" by item 3 of each & item 2 of each
> 
> The dictionary under “Sort Container” suggests what I want to do is possible:
> The sort container command is a stable sort. This means that if the sortKey for two items or lines is the same, sorting does not change their order, so you can do two successive sorts to create subcategories within the major sort categories.
> Tip: To create a custom sort order, use the each keyword to pass each line or item to a custom function. The value returned by the function is used as the sort key for that line or item. It is not currently possible to debug custom sort functions, and doing so could make the IDE unstable. It is recommended to use logging messages instead.
> The information in the “LiveCode Resource Center” doesn’t include an example of sorting on two criteria.
> 
> Thanks in advance for any thoughts you can share.
> 
> be well,
> randy
> 
> Randy Hengst
> www.classroomFocusedSoftware.com
> 
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list