Resizable DataGrid Question

Bob Sneidar bobs at twft.com
Mon Oct 24 14:16:50 EDT 2011


I am a little bit fuzzy as to why you cannot use the dgindex without the math? Why get the dgIndexes and subtract 1 from the offset? It seems the only reason your code works is by happy chance. It "just so happens" that subtracting 1 from the offset gives you the correct index number in this specific example. Or am I missing something? 

The only real reason to work with dgLine is to process through each line of the DISPLAYED data before moving on. Scrolling will still produce dgline 1-x, x = the number of visible lines. Once you sort, dgLine values get reassigned, but dgIndex is preserved. For an absolute reference to a specific row, dgIndex should be used exclusively, as every row has an index assigned, even those not not having been displayed yet. (Right?) The only thing altering the indexes is populating or repopulating the datagrid using dgText or dgData. 

At least this is my understanding of how it works. 

Bob


On Oct 24, 2011, at 10:32 AM, zryip theSlug wrote:

> 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
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list