Sort by item 1 and then item 2

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
LouisThompson
Posts: 4
Joined: Mon Oct 03, 2016 8:11 pm

Sort by item 1 and then item 2

Post by LouisThompson » Mon Oct 03, 2016 8:17 pm

Hi all,

I'm sure this is fairly simple but I can't get my head round it. I have a field which contains...

1 1
4 5
1 3
2 1
4 2
4 4
2 3
1 2
4 1
2 2
4 3
2 4
3 1
3 2

It like to sort it first by item 1 (Itemdelimiter is tab) and then item 2 so the field reads...

1 1
1 2
1 3
2 1
2 2
2 3
2 4
3 1
3 2
4 1
4 2
4 3
4 4
4 5

Any help would be gratefully appreciated.

Thanks

Louis

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 861
Joined: Fri Feb 06, 2015 4:03 pm

Re: Sort by item 1 and then item 2

Post by LiveCode_Panos » Mon Oct 03, 2016 8:58 pm

Hi Louis,

try this:

Code: Select all

on mouseUp
   set the itemdel to tab
   sort lines of fld 1 by item 2  of each
   sort lines of fld 1 by item 1  of each
end mouseUp
Best,
Panos
--

LouisThompson
Posts: 4
Joined: Mon Oct 03, 2016 8:11 pm

Re: Sort by item 1 and then item 2

Post by LouisThompson » Mon Oct 03, 2016 9:05 pm

Many thanks! Was sorting by item 1 first THEN item 2.
This works great!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Sort by item 1 and then item 2

Post by dunbarx » Tue Oct 04, 2016 2:11 am

You can do this in one line:

Sort this by sortKey1 & sortKey2 & ...

Craig Newman

Post Reply