Page 1 of 1

Datasorting

Posted: Mon Jan 23, 2017 11:53 pm
by pixeldamage
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?

Re: Datasorting

Posted: Tue Jan 24, 2017 4:13 am
by dunbarx
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

Re: Datasorting

Posted: Tue Jan 24, 2017 11:47 am
by Klaus
Hi pixeldamage,

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


Best

Klaus

Re: Datasorting

Posted: Tue Jan 24, 2017 3:41 pm
by dunbarx
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