Add custom class to...

185 views
Skip to first unread message

lyn2py

unread,
Nov 4, 2013, 2:51:49 AM11/4/13
to web...@googlegroups.com
I am using SQLFORM.grid and I need to wrap a big chunk of text (one of the data elements) in a CSS class called "big-chunk".

I remember it wasn't hard to add a CSS class to a dal field, but I can't seem to find the solution.

I tried this method:

db.define_table('table', 
    Field('combitext', 'text', represent=lambda x,row: XML(<div class="big-chunk">+x+</div>) ),
),

This works great except, when displaying the full grid, the text-heavy field would be output in a whole big chunk. Appadmin also displays the whole text when in table format.

I tried to limit the number of characters using maxtextlengths in SQLFORM.grid but it isn't working either (whole chunk of text appears). I know that from this experience it proves that db.table.field.represent will ensure that it will appear the way you want it to, but I only need it to appear like that when I click on "VIEW" on the grid.

Note: I need to wrap the value of the text output (in view mode) in a class, I do not need to add a class to a form field. thanks

I appreciate any help.

Anthony

unread,
Nov 4, 2013, 8:41:04 AM11/4/13
to web...@googlegroups.com
Maybe something like:

def mygrid():
   
if 'view' in request.args:
        db
.table.combitext.represent = lambda x, row: DIV(x, _class='big-chunk')
   
return dict(grid=SQLFORM.grid(db.table)

Anthony

lyn2py

unread,
Nov 4, 2013, 9:52:38 AM11/4/13
to web...@googlegroups.com
Thanks Anthony!
Reply all
Reply to author
Forward
0 new messages