This now means that we can implement and use a published state filter. Let's go to
the next stage, adding the ability to filter by a category. Unsurprisingly, we start in
much the same place, the JView's display method.
This example builds on the previous example and adds a category filter drop-down
selection box:
// prepare list array
$lists = array();
// get the user state of the published filter
$filter_state = $mainframe->getUserStateFromRequest(
>$option.'filter_state',
'filter_state');
$filter_catid = $mainframe->getUserStateFromRequest(
>
Chapter 8
[ 235 ]
$option.'filter_catid',
'filter_catid');
// set the table filter values
$lists['state'] = JHTML::_('grid.state', $filter_state);
$js = 'onchange="document.adminForm.submit();"';
$lists['catid'] = JHTML::_('list.category', 'filter_catid',
'com_myextension', (int)$filter_catid, $js);
// add the lists array to the object
$this->assignRef('lists', $lists);
This time we also retrieve the current value for filter_catid; there are no
restrictions on what we call filter form controls, but it is normal to prefix them with
filter_.
Pages:
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326