Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] Preffilled values from filters

[FIXED] Preffilled values from filters 23 Apr 2012 14:40 #2113

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
EDIT ADMIN : follows this post :

Thank you ! me too !!!


Just one more info:

I - When I started to use j-cook, and check my component in the sandbox, the behaviours of Filters was 'normal' between the grid (items view) and Form (new item).
If active filters were setted in the grid => they were auto selected when adding a new item.

I checked the generated code, and I think the job is prepared because I saw that to set the new data :
			$data->id_race = JRequest::getInt('filter_id_race');
			$data->id_etalon = JRequest::getInt('filter_id_etalon');
			$data->id_lice = JRequest::getInt('filter_id_lice');
			$data->id_statut = JRequest::getInt('filter_id_statut');

BUT ::

Here, the JRequest::getInt('filter_id_xxxxx'); always returns 0 (zero)

so I have added that in the item model to load the right filter value ...
	// for $filter_id_race, context never change to conserve filter on each page ...
	// $filter_id_race = $app->getUserStateFromRequest('filter.id_race', 'filter_id_race');

	$this->setState('filter.id_race', $filter_id_race, null, 'int');

Tell me when updated ...

Marc
Last Edit: 24 Apr 2012 08:37 by admin.
The administrator has disabled public write access.

Preffilled values from filters 24 Apr 2012 08:36 #2116

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
It probably went down, when I upgraded for the new MVC structure. (since 1.6)

I check this.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Preffilled values from filters 27 Apr 2012 08:12 #2155

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Everything is now working but not live yet.

I will tell you after the next upgrade (few days)
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Preffilled values from filters 30 Apr 2012 13:37 #2187

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Hi Joce !

Another question on this theme ...

I am trying to set some filters default value into the Items pages (grid).

Purpose is to prefit mains filters to obtain a usefull view. For me and my component, prefit the filter 'dogs status' to : 'Belong to the breed' (Appartient à l'élevage) to see directly all the dogs of my Breed ...

Also to present my component with prefitted filtered views...

So In 1.5 I was using the default value of filter, setting int ID instead of 'null' value. But with your code, it does not work.
$this->setState('filter.id_statut', $filter_id_statut, null, 'int');
$this->setState('filter.id_statut', $filter_id_statut, 2, 'int');

Why id is not retained and setted into the filter ?
Another way ?

Thanks

Marc.
Last Edit: 30 Apr 2012 13:40 by liubov.
The administrator has disabled public write access.

Re: Preffilled values from filters 01 May 2012 20:10 #2196

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Regarding Opened ticket, now it is working.
There has been lot of changes (layout name is not anymore included in the namespace for filters)


Now your problem :
$this->setState('filter.id_statut', $filter_id_statut, null, 'int');

This changes the state of the filter, but does not affect permanent session value.
You should change this at the level of JFactory::Application : (from memory)


JFactory::getApplication()->setUserState('filter.id_statut', $filter_id_statut);

EDIT :
$this->context = "com_xxxx.myview";
JFactory::getApplication()->setUserState($this->context . '.filter.id_statut', $filter_id_statut);
That's it
Coding is now a piece of cake
Last Edit: 01 May 2012 20:13 by admin.
The administrator has disabled public write access.
The following user(s) said Thank You: liubov

Re: Preffilled values from filters 02 May 2012 03:19 #2201

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Hi Jocelyn,

Tanks for your reply, but there were 2 questions in that post about filters:

1 => session filters => Thanks, ok I ve anderstood .
2 => default value filter, if i want to choose a defaut value, I set the id instead of null value, but no change into the view...
$this->setState('filter.id_statut', $filter_id_statut, 2, 'int');

( May be it was better to open another post for that... )

Marc.
The administrator has disabled public write access.

Re: Preffilled values from filters 02 May 2012 07:51 #2213

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Defaults states values of models :

The best place is in popolateState() function of the concerned model.
There, you can find getState() calls.
Define the default value within
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Preffilled values from filters 02 May 2012 09:29 #2217

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Completly agree with you, and it's what I've done.
	protected function populateState($ordering = null, $direction = null)
	   {
		// Initialise variables.
		$app = JFactory::getApplication();
		$session = JFactory::getSession();

		// Adjust the context to support modal layouts.
		if ($layout = JRequest::getVar('layout')) {
			$this->context .= '.'.$layout;
		}
		
		// for $filter_id_race context never change to conserve filter on each page ...
		$filter_id_race = $app->getUserStateFromRequest('filter.id_race', 'filter_id_race');
		$this->setState('filter.id_race', $filter_id_race, null, 'int');

                .....

		$filter_id_statut = $app->getUserStateFromRequest($this->context.'.filter.id_statut', 'filter_id_statut');
		$this->setState('filter.id_statut', $filter_id_statut, 2, 'int');

                ......

		parent::populateState();
	   }

Normaly, if $filter_id_statut is null (meaning no filtered), the default value '2' is setted to 'filter.id_statut', but as I said, it does not work...
Of course I can add a line to test the value of $filter_id_statut like that :
$filter_id_statut = $app->getUserStateFromRequest($this->context.'.filter.id_statut', 'filter_id_statut');
        if ( empty($filter_id_statut)) { 
            $this->setState('filter.id_statut', 2, null, 'int'); 
        } else {
            $this->setState('filter.id_statut', $filter_id_statut, null, 'int'); 
        }

it works, but it is not a nomal behaviours, isn't it ?


Marc.
Last Edit: 02 May 2012 09:48 by liubov.
The administrator has disabled public write access.
Time to create page: 0.077 seconds

Get Started