I recently posted a question about how to automatically select an item in a grid which is being populated by an HTTP dataset. I tried a solution posted by William Krick and this solution seemed to work. However, today I was noticing that when my grid contained more elements than were visible, the scroll bar didn't function correctly and I couldn't reliably page through the grid. I also noticed that my code to select the first item was being called multiple times when I would have only expected it to have been called once. I suspect that the problem has to do with how I had to change the implementation to work with a Grid, since William's example was for a combobox. I'm hoping that someone can help me see the error of my ways and offer a solution that works for grids.

Here is the code that I'm using:

   <class name="mygrid" extends="grid"
      <gridcolumn name="column1" ... >
         ...
      </gridcolumn>
      <gridcolumn name="column2" ... >
         <text font="Arial" fontstyle="bold">
            <datapath xpath="title/text()">             
               <method name="registerDelegate" args="v, event">
                  if ( this['dLastInit'] ) {
                      dLastInit.unregisterAll();
                  } else {
this.dLastInit = new LzDelegate( parent.parent.parent, '_selectFirst' );
                  }     
                  dLastInit.register( v, event );
               </method>
               <method args="clones" event="onclones">
                  registerDelegate( clones[clones.length-1], 'oninit' );
               </method>  
               <method args="data" event="ondata">
                  registerDelegate( parent, 'ondata' );
               </method>  
            </datapath>                           
         <text>
      </gridcolumn>
      <gridcolumn name="column3" ... >
         ...    
      </gridcolumn>
      <method name="_selectFirst">
         Debug.write("Selecting first item");
         selectItemAt(0);
      </method>                                                           
    </class>

I put the _selectFirst delegation code inside of one of the grid columns since I didn't know where else to put it. It's on the second column because I know that column will always have data. I instantiate on instance of 'mygrid' in my app and associate it with a dataset. When the data is retrieved, I see several 'Selecting first item' messages in the debugger which tells me the _selectFirst method is being called multiple times. This wouldn't be a major problem, but it seems that calling selectItemAt(0) messes things up. I also notice that when I scroll the grid, my _selectFirst method gets called. Perhaps this is what is messing up scrolling since as I move down the page, I'm continually telling the grid to selectItemAt(0). Can someone offer me some help on getting this selection operation to work correctly for a grid component?

Thanks.

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

Reply via email to