Datasorting

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
pixeldamage
Posts: 4
Joined: Tue Jan 03, 2017 1:14 pm

Datasorting

Post by pixeldamage » Mon Jan 23, 2017 11:53 pm

Hi,

This could be something really simple and I'm having a moment, but i've a list of IDs, names and scores in a data grid and i'm trying to pull out the list sorted so that it can be pushed to a graphics machine via AMCP commands.

I've got the data grid sorting perfectly, however when I try to pull out the data, it's not actually sorting it.

It's still sorting by IDs despite wanting to sort via codes. You have the data grid sorted, but the exported info is just as it was originally entered the first time around.

Code: Select all

on mouseUp pBtnNum
   set the dgProps["sort by column"] of group "dgResults" to "Time"
   
      if pBtnNum is 1 then
      
      put the dgData of group "dgResults" into theData 
      
      sort lines of it by theData[each]
              
      put theData[1]["Number"] into field "carnumber1"
      put theData[1]["Name"] into field "carname1"
      put theData[1]["Time"] into field "cartime1"
      put theData[2]["Number"] into field "carnumber2"
      put theData[2]["Name"] into field "carname2"
      put theData[2]["Time"] into field "cartime2"
      
      
   end if
   
end mouseUp


So visually it's sorting, but theData which is being pulled out is not in the right order. It could be something really simple, but I'd have thought what was visually listed in the grid is what would be spat out by the above in the order it's shown?

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

Re: Datasorting

Post by dunbarx » Tue Jan 24, 2017 4:13 am

Hi.

You are sorting the local variable "it" by a custom function. Well and good. But what is the value of "it"?

Also, the "dgData" is an array variable. You cannot sort an array variable. You first must transform it into an ordinary variable with the "combine" command.

Craig Newman

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Datasorting

Post by Klaus » Tue Jan 24, 2017 11:47 am

Hi pixeldamage,

please check this thread (Sort multidimensional array):
http://forums.livecode.com/viewtopic.php?f=7&t=28678


Best

Klaus

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

Re: Datasorting

Post by dunbarx » Tue Jan 24, 2017 3:41 pm

I do agree that one can indeed sort the keys of an array. I meant one cannot sort the elements of an array without transforming into an ordinary variable first.

Craig

Post Reply