Hi,

I have been trying waaaay too much to figure this out and have not  
been able to do so. I have seen several examples and suggestions in  
the forums but none of them have worked. I have the following piece  
of code:

<grid name="country_grid" width="100%" datapath="response/"
          contentdatapath="countries/country" sizetoheader="false">
   <attribute name="rowcolor" value="1" />

   <method name="alternate_color">
     <![CDATA[
     var pos = this.datapath.xpathQuery('position()');
     Debug.write(pos);

     if (pos % 2 == 0) {
       this.setAttribute('rowcolor', 0xeeeeff);
     } else {
       this.setAttribute('rowcolor', 0xffffff);
     }
     this.setBGColor(this.rowcolor);
     ]]>
   </method>

   <gridcolumn editable="false" width="25" sortable="false"  
resizable="false">#
     <text datapath="position()">
       <method event="ondata" args="d">
         <![CDATA[
           parent.rowcolor = d;
           Debug.write("Position ", d, this.datapath.xpathQuery 
('position()'));
         ]]>
       </method>
     </text>
   </gridcolumn>
   <gridcolumn editable="false" width="40">Code
     <text datapath="code/text()">
       <method event="ondata" args="d">
         <![CDATA[
           Debug.write("Got data ", d, this.datapath.xpathQuery 
('position()'), parent.rowcolor);
         ]]>
       </method>
     </text>
   </gridcolumn>
   <gridcolumn editable="false" width="460">Name
     <text datapath="name/text()" />
   </gridcolumn>
</grid>

When executed, the grid populates just fine showing all the right  
contents, including the numbered '#' column. Also, when this same  
column (#) is 'rendered', the debugger shows the right thing (e.g.  
Position 1 1, Position 2 2, Position 3 3, etc).

However, when the column 'Code' is rendered, the debugger shows the  
wrong thing (e.g. Got data AR 1 <<undefined>>, Got data AQ 1  
<<undefined>>, Got data AM 1 <<undefined>>, etc). It seems that when  
rendering the 'Code' column, xpathQuery('position()') is always  
returning 1. Also, the assignment to parent.rowcolor when rendering  
the '#' is not "persisting" for the other columns.

For "debugging" purposes, the method named "alternate_color" is never  
used. I had originally put that as an event="ondata", but that didn't  
work, so I was trying to isolate the problem.

Why is it so difficult for me (or may be many of us) to render a grid  
with alternating row colors? Any help would be greatly appreciated  
since I'm stuck at this juncture.

Thanks,
Daniel

_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to