| 232 | |
| 233 | ==== Default Filters ==== |
| 234 | A !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 | |
| 236 | To instruct a FilterForm to NOT implement the default filters, add {{{?default_filters=0}}} to the URL. |
| 237 | |
| 238 | Example: Filter Staff by a User's (Branch) Organisation, add this to the controller: |
| 239 | {{{ |
| 240 | def 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 | |
| 249 | from s3 import s3_set_default_filter |
| 250 | s3_set_default_filter("~.organisation_id", |
| 251 | user_org_default_filter, |
| 252 | tablename = "hrm_human_resource") |
| 253 | }}} |