Resizable DataGrid Question
zryip theSlug
zryip.theslug at gmail.com
Mon Oct 24 13:32:50 EDT 2011
On Thu, Oct 20, 2011 at 12:34 AM, Mike Doub <Mike at doub.com> wrote:
> I am not sure that you can assume that the indexes always going to
> correspond to the display order. This is why I decided to use dgIndex
> function as it returns the indexes in the display order. I do plan on
> having multiple sorting options.
Indeed, we can't assume that the dgIndex and the dgLine will return
the same value after sorting the list. And that was exactly the reason
I chosen to use dgLine instead of dgData after testing.
Why? Let's explore a small array of three names and their respective indexes:
[firstname][1] = "Mike"
[firstname][2] = "zryip"
[firstname][3] = "Dave"
Indexes for the firstname column are : 1,2,3
Now apply an ascending sort to our column firstname. The result is:
[firstname][3] = "Dave"
[firstname][1] = "Mike"
[firstname][2] = "Zryip"
Indexes for the firstname column are now : 3,1,2
Now we can explore your code:
put the dgIndexes of me into tList
-- Here tList for our sorting column will contain indexes in their
current order: 3,1,2
-- Considering we are currently filling data for the second row, the
dgIndex for row 2 is 1
put itemoffset(tIndex,tList) into toff -- itemoffset(1,"3,1,2")
-- will return 2, which is actually the number of our second row.
put item (toff -1) of tList into tpreIndex --find the current index
in the ordered list
-- The previous index of index (2 - 1) in the dgIndexes is 3.
By using this code:
put the dgIndexes of me into tList
put itemoffset(tIndex,tList) into toff
put item (toff -1) of tList into tpreIndex
You are in fact searching the location of the previous dgIndex in the
rows order, so you are doing something equivalent to:
put (the dgLine of me - 1) into tThePreviousLine
In conclusion using your code or using dgLine - 1 to get the previous
value linked to the array index, have an equivalent result.
Best regards,
--
-Zryip TheSlug- wish you the best! 8)
http://www.aslugontheroad.co.cc
More information about the use-livecode
mailing list