Changes between Version 63 and Version 64 of S3/FilterForms


Ignore:
Timestamp:
08/30/19 09:36:21 (3 years ago)
Author:
Fran Boon
Comment:

Default Filters

Legend:

Unmodified
Added
Removed
Modified
  • S3/FilterForms

    v63 v64  
    230230
    231231  ''Note'': if formstyle returns a TR, a list of TRs or a TAG[""] of TRs, then the filter form will be rendered as a TABLE - otherwise as DIV.
     232
     233==== Default Filters ====
     234A !FilterForm can be instructed to set it's status to default values for the convenience of interactive users. This allows their initial view to be filtered, yet allow them to unfilter to whatever their security permissions, or any other 'hard' filter allows.
     235
     236To instruct a FilterForm to NOT implement the default filters, add {{{?default_filters=0}}} to the URL.
     237
     238Example: Filter Staff by a User's (Branch) Organisation, add this to the controller:
     239{{{
     240def user_org_default_filter(selector, tablename=None):
     241    auth = current.auth
     242    user_org_id = auth.is_logged_in() and auth.user.organisation_id
     243    if user_org_id:
     244        return user_org_id
     245    else:
     246        # no default
     247        return {}
     248
     249from s3 import s3_set_default_filter
     250s3_set_default_filter("~.organisation_id",
     251                      user_org_default_filter,
     252                      tablename = "hrm_human_resource")
     253}}}
    232254== Development ==
    233255