PDA

View Full Version : get data from grid row


mai
04-15-2004, 07:07 PM
Hi

I have question about grid component.
Can I get the value of gridtext/gridcolumn from
selected row?

antun
04-16-2004, 09:45 AM
Yes, you can get at the data that drives the grid:


<canvas debug="true" maxtextwidth="1000">

<dataset name="contacts" request="true"
src="http://laszlosystems.com/lps/sample-apps/contacts/contactsdata.xml"/>

<simplelayout axis="y" spacing="10" />

<grid id="foo" datapath="contacts:/resultset">
<gridcolumn showheader="false" width="50">
<view bgcolor="#CCCCCC" width="${parent.width}"
placement="header"
height="${parent.immediateParent.height-1}"/>
<text datapath="position()"/>
</gridcolumn>
<gridcolumn width="200"> Name
<text datapath="@displayname"/>
</gridcolumn>
<gridcolumn sortable="false"> Home
<checkbox value="$path{'@home_default'}"
xoffset="${10-parent.width/2}">
<method event="onvalue">
this.datapath.updateData();
</method>
</checkbox>
</gridcolumn>
</grid>

<button>Get selection
<method event="onclick">
<![CDATA[
Debug.write( "== Getting selection =======" );
var sel = foo.getSelection();

// getSelection returns an array of datapointers,
// so loop through it
for ( var i=0; i<sel.length; i++ ) {
Debug.write( "Selection number " + i );
var dp = sel[i];
// Here's some data that is exposed in the datagrid:
Debug.write( "Display Name: " + dp.p.attributes.displayname );
// ... and some that is not:
Debug.write( "email: " + dp.p.attributes.email );
}
]]>
</method>
</button>

</canvas>


Make a selection (single or multiple) and then click the button. You're actually getting the value from the XML. getSelection() returns a pointer to the LzDataElement (an XML node in the dataset), so you can get to data that the grid doesn't even show.

-Antun

mai
04-18-2004, 05:42 PM
Hi Antun

Thank you very much. Your reply is very helpful!

The only difference is that my dataset contains xml elements, not attributes.
In that case instead of "dp.p.attributes.email" I have to code something like this: dp.xpathQuery('email/text()'). See attached repgrid.lzx.

Again,
Thanks a lot.

-- mai --

antun
04-19-2004, 09:27 AM
The only difference is that my dataset contains xml elements, not attributes.
In that case instead of "dp.p.attributes.email" I have to code something like this: dp.xpathQuery('email/text()'). See attached repgrid.lzx.

Well noticed. I've filed a feature request to have a getNodeText() method added to LzDataElement (which is the object that datapath.p refers to).

Another way of getting at the node text is:


var nodeText = new LzDatapointer( null, { p : dp.p} ).getNodeText();


... where you create a new instance of LzDatapointer (which has a getNodeText() method) and set its p attribute to the value of dp.p before calling getNodeText().

-Antun