[web2py] Re: color cells based on value in SQLFORM

2014-05-15 Thread villas
Here is a Bootstrap way which displays well enough in the grid. Easy but not so flexible ... qstatus_labels = dict(Draft='label label-info', Open='label label-warning', Closed='label label-danger', Won='label label

[web2py] Re: color cells based on value in SQLFORM

2014-05-12 Thread Anthony
Keep in mind, this method will execute a separate database select for every row in the table in order to retrieve the status highlight_color. Also, the CSS rule will not color the background of the entire cell, just the status text (plus padding). Anthony On Monday, May 12, 2014 7:33:06 PM UTC

[web2py] Re: color cells based on value in SQLFORM

2014-05-12 Thread Michael Beller
I wouldn't recommend using field names, that would not be very flexible. Here's an option: db.define.table('status', Field('name'), Field('highlight_color')) db.define.table('inventory', Field('item'), Field('status', 'reference status')) Then just populate the status table wit

[web2py] Re: color cells based on value in SQLFORM

2014-05-12 Thread LoveWeb2py
Thank you for your reply, Michael & Anthony. Michael: I really like this idea. What would my model look like? I setup db.define_table('status', Field('id','integer'), Field('normal','string'), Field('warning','string'), migrate=False) Would I have to populate the fields or ca

[web2py] Re: color cells based on value in SQLFORM

2014-05-10 Thread Anthony
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

[web2py] Re: color cells based on value in SQLFORM

2014-05-10 Thread Michael Beller
I learned this method from one of Massimo's lecture video's: At the top of your model file: # function to allow models to set status style def show_status(status,row=None): return SPAN(status.f_name.replace(' ','_'),_class=status.f_name) ifstatus else status After your table definition (coul

[web2py] Re: color cells based on value in SQLFORM

2014-05-09 Thread Anthony
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: ' +