My new approach is use TABLE() helper with TR() and TD(). However I lost my
header! I need this because sometimes is useful for the user order table by
items. Suggestions?
def myformat(rows):
#import gluon
#nuevo = gluon.dal.Rows()
new = TABLE()
for i in rows:
if i.account.startswith('A'):
row = TR(TD(i.account), TD(i.concept), _class='green')
new.append(row)
elif i.account.startswith('B'):
row = TR(TD(i.account), TD(i.concept), _class='orange')
new.append(row)
else:
row = TR(TD(i.account), TD(i.concept), _class='blue')
new.append(row)
return new
On Monday, January 6, 2014 10:22:00 AM UTC-6, Omar Meat Boy Gutiérrez wrote:
>
>
> I am using SQLFORM.grid. I'd like to classify data with colors, for
> example:
>
> ________________________________________________________________
> | If data in first row is type A | I'd apply the
> green color to row. |
>
> -----------------------------------------------------------------------------------------------------------------
> | If data in second row is type B | I'd apply the red color
> to row. |
>
> -----------------------------------------------------------------------------------------------------------------
> And so on.
>
> I am using the advice explained in other questions:
>
> customized = myformat(grid.rows)
> grid.element('.web2py_table', replace=customized)
>
> Where my customize function is:
>
> def myformat(rows):
> #import gluon
> #nuevo = gluon.dal.Rows()
> new = DIV()
> for i in rows:
> if i.account.startswith('A'):
> # in this section I need to paint the row in green
> i.account = ('<div style="color:green;">' + i.account +
> '</div>') #my try
> elif i.account.startswith('B'):
> # in this section I need to paint the row in red
> i.account = ('<div style="color:red;">' + i.account + '</div>'
> ) #my try
> new.insert(0, i)
> return new
>
> However I am getting only string data:
>
> <Row {'type': '<div style="color:green;">A</div>}> <Row {'type': '<div
> style="color:red;">B</div>}>
>
> I don't know what kind of value I must return from myformat function. Rows
> or DIV. Which way should I go?
>
>
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.