Not tested, but another option would be to keep something like your current 
code (though you can simplify by creating just a single version of the SPAN 
code and fill in the color via a lookup in a dictionary, as in my previous 
example), but instead of setting style attributes in your represent 
functions, just set CSS classes (e.g., SPAN(value, _class='green-cell')). 
Then use jQuery to set the background colors of the table cells:

$('.web2py-table td .green-cell').parent().css({background: "green"});

Anthony

On Friday, May 9, 2014 10:07:07 PM UTC-4, Anthony wrote:
>
> Might be easiest to do this with Javascript in the browser. You can also 
> manipulate the grid DOM on the server -- maybe something like this:
>
> colors = {1: 'green', 2: 'yellow', 3: 'red'}
> grid = SQLFORM.grid(...)
> table = grid.element('.web2py_table')
> if table:
>     [td.update(_style='background: ' + colors.get(td[0], 'orange'))
>      for td in table.elements('td')]
>
> That may be a bit slow because it must traverse the whole table to find 
> the TDs and then iterate over the TDs to update their attributes.
>
> Anthony
>
> On Friday, May 9, 2014 4:22:45 PM UTC-4, LoveWeb2py wrote:
>>
>> Hello,
>>
>> I have a spreadsheet of items and I want to track their inventory based 
>> on color (similar to an excel spreadsheet).
>>
>> I have two columns for example: Item, Item_Status
>> The item could be a desk, chair, etc... and for status I have 1 2 or 3.
>>
>> If the status is 1 I would like to make the cell color of the desk green, 
>> 2 yellow, 3 red.
>>
>> so far I have 
>>
>> def represent_colored(value):
>>    if value == 1:
>>    return SPAN(value,_style="background-color:green',)
>> elif value == 2:
>>    return SPAN(value,_style="background-color:yellow',)
>> elif value == 3:
>>    return SPAN(value,_style="background-color:red',)
>> else:
>>    return SPAN(value,_style="background-color:orange',)
>>
>> def inventory():
>>    db.inventory.items.represent = lambda value, row: 
>> represent_colored(value)
>>    grid=SQLFORM.grid(db.inventory, paginate=20)
>>    return dict(grid=grid)
>>
>> This works so far, but it only changes the background color of the text 
>> in the status column and I want to change the column of the actual item. I 
>> also would like to change the entire cell <td> instead of just the 
>> background behind the text.
>> Also, I plan on branching the inventory out to multiple columns and I 
>> have two questions:
>>
>> 1) How could I change the entire cell color?
>> 2) Is making multiple "status" columns the most efficient and pythonic 
>> way to accomplish this.
>>
>> You guys are the best!
>>
>>
>> Wil
>>    
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to