We are developing a custom component in joomla 3.X. We have a list view and added some custom filters on the top of the list. Our problem is, that there will be too many results if no filter applied. We are wondering how we could set a default value for the filter when the pages loads for the first time.

We have tried it in the constructor of the model or in the populatestate method, but without success.

$app = JFactory::getAplication();
 $from_date = $app ->getUserStateFromRequest();

 $date = date('Y-m-d H:i:s');

 if($from_date === null)
  $from_date = $date;

Unfortunately it did not work and could not find a way of setting it. Thanks!


1 Answer 1


Have a look at the JModelList::populateState() at the backend of any core component, such as com_banners.

You can use the getUserStateFromRequest method to set a default value. See 3rd parameter, $default.

 * Gets the value of a user state variable and sets it in the session
 * This is the same as the method in JApplication except that this also can optionally
 * force you back to the first page when a filter has changed
 * @param   string   $key        The key of the user state variable.
 * @param   string   $request    The name of the variable passed in a request.
 * @param   string   $default    The default value for the variable if not found. Optional.
 * @param   string   $type       Filter for the variable, for valid values see {@link JFilterInput::clean()}. Optional.
 * @param   boolean  $resetPage  If true, the limitstart in request is set to zero
 * @return  The request user state.
 * @since   12.2
public function getUserStateFromRequest($key, $request, $default = null, $type = 'none', $resetPage = true)

Does this help?

  • This solution means that it will not be possible to clear the filter and view all the records. This might be a problem in some cases.
    – Dom
    Jun 3, 2019 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.