Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

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

  • VeCrea
  • VeCrea's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  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)

Please Log in or Create an account to join the conversation.

Last edit: by VeCrea.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.074 seconds

I jumped and started to work on a demo component... but 2 days later this demo component became the real component. I just showed today the end result to my customer and he turned to me and said... "this is more than I expected"... All of this is because Cook did cut about 70% of my work and provided me more ways to improve the usability of the component. The end result was 17 tables all related between than to generate a full dashboard for the travel agents. Thanks for Cook developers for such great tool. This component would not be possible to be done at short time with all the features in it
Griiettner (Forum)  

Get Started