Page 1 of 1

sorting problem

Posted: Tue Jan 22, 2013 12:25 pm
by user#606
I have a table field with column 7 (item 7) that contains a type of user, as a value. These might be, Architect or Builder or Developer.
I want the table to sort so, for example all the lines with Builders in (item 7) are at the top of the displayed table.
According to the Dictionary, sort container is the way to do this. however it is not clear how it is implemented, because all combinations I have tried do not work. I show below the code that sorts the text, but without the part I cannot get right. The part I need help with.

Code: Select all

on scrollbarBeginning 
  set the itemDelimiter to tab
   sort lines  of  field "table 1" ascending text by item 7 of each 
end scrollbarBeginning

on scrollbarEnd -- use a scroll bar to navigate among cards
  set the itemDelimiter to tab
   sort lines  of  field "table 1" descending text by item 7 of each 
end scrollbarEnd
If it helps to see the simple stack, I can email it. ajperks@webplus.net

There is another oddity as well, and if I had hair, I would have pulled it all out by now.
Each column in the table has scrollbar arrows as sort controls. Just the arrows, not the bit between as well. This works well as Shift Click on the arrow head and is neat, also.
Column 5 and 6 both contain dates, col 6 works, but col 5 does not. the only difference between them is the number 5 for item 5 and 6 for item 6. the code was duplicated with the scroll control and renamed. The item numbers have been changed of course.
If I change the 5's to 6's, column 6 sorts, so the code is working. however, if I change the code in col 6 to 5's then Col 5 still refuses to work.
I have made sure the dates in col 5 only contain properly formatted dates, only.
So, why will column 5 not work?

Your help on both would be appreciated.

Re: sorting problem

Posted: Tue Jan 22, 2013 2:45 pm
by bn
Hi,

Alan has sent me his stack and we will see how it goes.

Kind regards

Berns

Re: sorting problem

Posted: Tue Jan 22, 2013 3:10 pm
by dunbarx
Hi.

Your script seemed fine, so I made a table field similar to yours, and it works like a charm. Something else is going on.

Do what I did. Make a new table field with a few columns. Put some numerical data in it, and run your script accordingly, maybe sorting up and down a few times so you see it works. Now go to your original field and see what the difference is, or what else is going on within it.

Craig Newman

Re: sorting problem

Posted: Tue Jan 22, 2013 3:55 pm
by sturgis
since you're sorting a column of dates which isn't sortable by numeric or plain old text method you have to specify the type of sort as dateTime. There is an example of exactly that in the dictionary.

It is also a good idea to specify numeric on numeric columns of course.
The sortType is one of text, international, numeric, or dateTime. If you don't specify a sortType, the sort is by text.

Re: sorting problem

Posted: Tue Jan 22, 2013 4:24 pm
by bn
Hi,

problem solved. It was partly a problem of setting the "set the useSystemDate to true" before sorting since the dates were in systemDate format.
And a problem with is partial sort that was taken care of by a function
like in

Code: Select all

local sSortKey

on mouseDown
   put field "input7" into sSortKey
end mouseDown

on scrollbarBeginning 
  set the itemDelimiter to tab
  sort lines  of  field "table 1" ascending numeric by sortMyKey (item 7 of each)
end scrollbarBeginning

on scrollbarEnd 
   set the itemDelimiter to tab
   sort lines  of  field "table 1" descending numeric by sortMyKey (item 7 of each)
end scrollbarEnd

function sortMyKey pKey
   if pKey = sSortKey then
      return 1
   else 
      return 2
   end if
end sortMyKey
seems to work alright

Kind regards

Bernd