Also, using the .element() and .elements() methods provides some powerful 
options for searching the DOM -- 
see http://web2py.com/book/default/chapter/05#Server-side-DOM-and-Parsing.

Anthony

On Friday, November 11, 2011 5:37:52 PM UTC-5, Cliff wrote:
>
> Props to Richard Vezina for posting a similar technique.  This is 
> built on his post 
>
> From the book we know that, "Components' objects can be referenced via 
> their position, and helpers act as lists with respect to their 
> components." 
>
> A little archaeology in the source code tells us that SQLFORM.grid 
> emits a DIV object.  When there's an index table involved, the DIV has 
> three components: a DIV, a DIV containing a TABLE and another DIV. 
>
>  # first we get the grid 
>  grid = SQLFORM.grid(query) 
>
>     # examine the div at the top of the grid div 
>     # for index lists, this div is of the class 'console', 
>     # so look for 'console' near the start of the div 
>     # there is CERTAINLY a better way to detect an index table, but 
> this works 
>     if 'console' in str(grid[0])[0:35]: 
>         ## grid[1][0][1] is the DIV, TABLE and TBODY 
>         ## so we iterate over TRs in the table body 
>         for row in grid[1][0][1]: 
>             ## TR acts like a list, so we use some Python list fu 
>             row.insert(-1, 'foo') 
>     return dict(grid=grid) 
>
> Done.  Haven't cleaned up the table head yet, but it should be 
> similar. 
>

Reply via email to