Hello,

I have these 2 tables opt and opt_cat, where opt depends on opt_cat for the 
category name and other settings.

db.define_table('opt',
                Field('name', 'string', label=T('Name'), length=NAME_LEN, 
notnull=True,
                      required=True, unique=True),
                Field('opt_cat_id', 'reference opt_cat', label=T('Category'
),
                      notnull=True, required=True),
                auth.signature,
                format='%(name)s',
                )

db.define_table('opt_cat',
                Field('name', 'string', label=T('Name in Portuguese'), 
length=NAME_LEN,
                      notnull=True, required=True, unique=True),
                Field('name_en', 'string', label=T('Name in English'),
                      length=NAME_LEN, notnull=True, required=True, unique=
True),
                Field('mandatory', 'boolean', default=False,
                      label=T('Mandatory'), notnull=True, required=True),
                Field('one_opt_only', 'boolean', default=False,
                      label=T('One option only'), notnull=True, required=
True),
                auth.signature,
                format='%(name)s',
                )

I was testing grid sort and found that a grid like this

        table = db.opt

        grid = SQLFORM.grid(
            table,
            csv=False,
            details=False,
            maxtextlength=GRID_COL_LEN_FOR_TEXT,
            ondelete=on_delete,  # Grid only.
            onvalidation=on_validation,  # Form only.
            orderby=db.opt.name,
            paginate=session.auth.user.pagination,
            # represent_none='',  # Grid and view form only.
        )

will sort by opt_cat_id and not by the opt_cat.name that is shown.
The only solution I've found is to make a join between the 2 columns and 
show the client.name directly.

        query = db.opt.opt_cat_id == db.opt_cat.id

        grid = SQLFORM.grid(
            query,
            csv=False,
            details=False,
            field_id=db.opt.id,
            fields=[
                db.opt.name,
                db.opt_cat.name,
                db.opt_cat.name_en,
            ],
            headers={'opt_cat.name': T('Category'), 'opt_cat.name_en': T(
'Category')},
            maxtextlength=GRID_COL_LEN_FOR_TEXT,
            ondelete=on_delete,  # Grid only.
            onvalidation=on_validation,  # Form only.
            orderby=db.opt.name,
            paginate=session.auth.user.pagination,
            # represent_none='',  # Grid and view form only.
        )


Is there a better solution?

Another question is that I see that the sorting is ASCII based (small case 
after upper case).

Is there any way to make it sort without being case sensitive?


Thanks,

JM

-- 
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