Thanks Niphlod I understand that the web2py grid cannot do all that users would like to, but for my use it's quite to. Viewing, sorting, editing, creating new rows, I like it. For my needs it just miss a way for sorting rows properly by fields that contain an row id of another table. If there's a way to sort and search by the represent function or format instead of id I think that we will have more the possibility to use the web2py grid. I'm afraid that I don't understand your explanation about how to do it. The represent function don't change anything, almost as I've done it. If you have a suggestion thank you.
DB: db.define_table('l1_categories', Field('name'), format = '%(name)s') db.define_table('l2_categories', Field('on_line', type='boolean', default=True, label='Online'), Field('l1_category', 'reference l1_categories', represent=lambda id, r: db.l1_categories[id].name), Field('name'), format=lambda row: '%s - %s' % (row.l1_category.name, row.name)) With this controller the user can order by l1_categories.name but the details view don't show the l1_categories.name, only the id: query = db.l1_categories.id==db.l2_categories.l1_category fields = (db.l1_categories.name,db.l2_categories.name) grid = SQLFORM.grid(query=query, fields=fields, csv=False, links_in_grid=False, links=None, searchable=False, editable=True, deletable=False, create=True, details=False, buttons_placement = 'left') With this controller order is made by l2_categories.l1_category but the details view show the the l1_categories.name query = db.l2_categories fields = (db.l2_categories.l1_category,db.l2_categories.name) grid = SQLFORM.grid(query=query, fields=fields, csv=False, links_in_grid=False, links=None, searchable=False, editable=True, deletable=False, create=True, details=False, buttons_placement = 'left') Is there a way to sort by name instead of id and seeing the field name in the details view ? Il giorno mercoledì 21 gennaio 2015 20:50:06 UTC+1, Niphlod ha scritto: > > irregardless of the "business logic" there's a simple caveat with web2py > grid (and reference fields in general). > for a field to be ordered (or searched, as it poses the exact same deal) > correctly, web2py would have to fetch for each row of the table (not the > page, the entire table) the reference record and build the string > representation for it. > Of course, this would mean killing performances at any level and with any > backend. > > "represent" can also accept a function, that further reduces the > possibilities. references are a "subset" of the issue, that can be > circumvented with a proper join and leaving the "leftiest" table (along > with the correct field_id) as the one you'd like to edit. > > that being said, the grid is not (and can't be) a silver-bullet for every > "business logic", but it closes most of the "needs" with little > modification to the one-liner solution.... > -- 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.