Welcome, Guest
Username: Password: Remember me

TOPIC: Default Value for Filters (Range,...)

Default Value for Filters (Range,...) 03 Oct 2013 06:52 #11290

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
  if ($('#filter_reportdate_from').val() == ""){
	  var dateDeb = new Date();
	  var leMois = Number(dateDeb.getMonth())+1;
	  var annee = dateDeb.getFullYear();
	  var laDateDeb = "01."+leMois+"."+annee;
	  $('#filter_reportdate_from').val(laDateDeb);
	  adminForm.submit()
  }
Just to know if my coding is correct : i want to set a range From filter field to the first day of the month if nothing has been chosen (so when the user first arrives on the page). (It works, i just want to know if i could code it better)
Last Edit: 03 Oct 2013 06:52 by VeCrea.
The administrator has disabled public write access.

Default Value for Filters (Range,...) 10 Oct 2013 00:13 #11361

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Better in PHP.

In the view file, BEFORE to call getItems()
$model->setState('filter.reportdate_from', $dateDeb->toSql());

Assuming $dateDeb is a JDate Object initializated as you want.
You must read the state before to set default value :
if (!$model->getState('filter.reportdate_from'))

Be careful with JDate::toSql() function (in my example) it is only supported by Joomla 3.0. You must use the helper to make this code cross compatible.
XxxxHelperDates::toSql($dateDeb)

Hope it helps.
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.087 seconds

Get Started