PDA

View Full Version : Grid: how do I get get data using $path{}?


millejos
02-02-2007, 08:26 AM
I've searched the forums fairly thoroughly and haven't found the answer yet so I'm posting this question: How do I retrieve row data from within a grid using $path{}? Here's an example of what I mean:


<dataset name="data">
<VenueList>
<Venue Id="1" Name="Fred" Link="http://www.google.com" />
<Venue Id="2" Name="Bob" Link="http://www.yahoo.com" />
</VenueList>
</dataset>

<grid name="chart" datapath="data:/VenueList">
<!-- column 1 -->
<gridcolumn width="${parent.width * 0.10}" clip="true">Id
<attribute name="link" type="string" value="$path{'@Link'}"/>
<text datapath="@Id">
<handler name="onclick">
Debug.write(parent.link);
</handler>
</text>
</gridcolumn>
<!-- column 2 -->
<gridcolumn width="${parent.width * 0.10}" clip="true">Name
<datapointer name="link" datapath="@Link"/>
<text datapath="@Name">
<handler name="onclick">
Debug.write(parent.link);
</handler>
</text>
</gridcolumn>
</grid>


I've tried using both an <attribute> with $path{} and a <datapointer> tag with datapath pointing to the row attribute I want with no luck. The text tag of course has no issues getting the value. I guess I could use a hidden text tag to store that value for the row but... :( Can anyone show me what I'm doing wrong?

senshi
02-02-2007, 09:29 AM
You have to differentiate between a grid-column and a grid-row.
So, check out parent and immediateparent of the text, you will see the difference:
parent is the column, which is specified in the lzx-file. Doesn't have any data.
immediateparent is the row (will be constructed automatically). Contains the actual data.


So, I would propose adding the attribute link to your text:

<!-- column 1 -->
<gridcolumn width="${parent.width * 0.10}" clip="true">Id
<attribute name="link" type="string" value="$path{'@Link'}"/><!-- won't work -->
<text datapath="@Id">
<attribute name="link" type="string" value="$path{'@Link'}"/><!-- will work -->
<handler name="onclick">
Debug.write( "this:", this );
Debug.write( "parent:", parent );
Debug.write( "immediateparent:", immediateparent );
//
Debug.write( "parent.datapath:", parent.datapath );
Debug.write( "immediateparent.datapath:", immediateparent.datapath );
//
Debug.write( "parent.link:", parent.link );
Debug.write( "this.link:", this.link );
</handler>
</text>
</gridcolumn>

millejos
02-02-2007, 09:50 AM
Thanks senshi, your explaination really helps! I hadn't understood the difference between parent and immediateparent.

For anyone else reading this, there seems to be some more documentation on immediateparent (http://www.openlaszlo.org/lps/docs/guide/class-inheritance.html) at point 7.3.2. ImmediateParent