wiki:AlphaSort

Version 1 (modified by Fran Boon, 15 years ago) ( diff )

--

AlphaSort

Want to be able to sort a Dropdown alphabetically to make it easier for data entry e.g. the Organisations dropdown in 'Add Office'

We have 2 sorts of dropdowns:

  • Database
  • Dictionary

This one is a Database one using the IS_ONE_OF() custom validator from modules/validators.pty

js list sorter:

As far as sorting right in the backend is concerned - models/05_or.py line 107, tried putting .select(orderby = db.or_organsation.name)[0]... But that did not work out...

Q: If its possible to put a javascript fix where does one put a page specific js ?
A: views/module/resource_method.html

For Dictionary-based ones:

In  models/05_or.py change:

or_organisation_type_opts = {
   1:T('Government'),
   2:T('International Governmental Organization'),
   3:T('International NGO'),
   4:T('Misc'),
   5:T('National Institution'),
   6:T('National NGO'),
   7:T('United Nations')
   }
...
db[table].type.requires = IS_NULL_OR(IS_IN_SET(or_organisation_type_opts))

into

or_organisation_type_opts = [
   (1,T('Government')),
   (2,T('International Governmental Organization')),
   (3,T('International NGO')),
   (4,T('Misc')),
   (5,T('National Institution')),
   (6,T('National NGO')),
   (7,T('United Nations'))
]
...
db[table].type.requires = IS_NULL_OR(IS_IN_SET(
   [x[0] for x in or_organisation_type_opts],
   [x[1] for x in or_organisation_type_opts]))
Note: See TracWiki for help on using the wiki.