Welcome, Guest
Username: Password: Remember me

TOPIC: [SOLVED] Filters - can't reset

[SOLVED] Filters - can't reset 19 May 2013 15:16 #7208

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
Hi,

I found some problems with the filters. When the result of the select involves a join, the filter does not work.
I fixed it by creating a custom context and adapting the code from a "simple" filter that is working. The data are shown correctly but I'm struggling since I can't find the way to reset the filter.

When the page is reloaded with the filtered values, the filter show the null value and the selected key only and, most of all, the null value is not selectable! In the working example I followed, the refreshed select shows all the keys and the null label is selectable (as it is originally in the page, when loaded the first time).
It is possibile to go back to the original view by pressing the "Back button" of the browsert, but I would like to understand how to properly reset the filter!

Can anyone PLEASE point me in the right direction? Can't find what I'm missing. Here's the code.

Inside view.html.php I have added :
$model_id_registry = JModel::getInstance('authors', 'MantaModel');
$model_id_registry->setState('context', 'authors.registry');
$this->filters['id'] = new stdClass();
$this->filters['id']->list = $model_id_registry->getItems();		
$this->filters['id']->value = $model->getState("filter.id");

Inside default_filters.php, inside the resetFilters
if (jQuery('filter_id') != null){
jQuery('filter_id').value='';
}

Then, inside <fieldset id=filters ...>
<div class='filter filter_id'>
<label class='filter' for="filter_id"><?php echo(JText::_("MANTA_JSEARCH_STH")); ?> :</label>
<?php echo JDom::_('html.form.input.select', array(
		'dataKey' => 'filter_id',
		'dataValue'=> (int)$this->filters['id']->value,
		'list' => $this->filters['id']->list,
		'labelKey' => '_registry_id_auth_name',
		'nullLabel' => "MANTA_FILTER_NULL_STH",
		'submitEventName' => 'onchange'
			));
?>
</div>

What am I missing ?!?!?!?
Last Edit: 19 May 2013 15:17 by dieda1821.
The administrator has disabled public write access.

Re: Filters - can't reset 19 May 2013 15:19 #7209

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
I forgot to add that the I'm referring to a Backend collection view.
The administrator has disabled public write access.

Re: Filters - can't reset 12 Jun 2013 03:54 #7437

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
And if you try to filter on another value than 'id' ?

Because 'id' is kind of special in the model and with the states.
I didn't digged into your problem, but firstly you cannot do bad changing the name of this key.

If you filter on id (unique), you will always get only 1 record.
In that case, you must use an 'item' layout.

I think it didn't answered you, but can you please try thoses test on another var.

With the use of the context state (as you did), the filters permanent values are separated depending of this context. For instance, if you have another context for ajax, then the list filters will not apply on the ajax selection because the context is keeping separate the values of filters.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Filters - can't reset 12 Jun 2013 08:11 #7448

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
Hi admin!

Thanks for the answer! The point is that I can't send inside the filtering query a different value from an id (internal or external)!
I (try to) explain myself better: I can populate the dropdown with values from a second table, but the value sent is ALWAYS (at least in my trials) the corresponding id.

The core code I think is the following (suppose the collections name is "authors"), inside admin/models/authors/view.html.php
$model_registry_id = JModel::getInstance('authors', 'MantaModel');
		$model_registry_id->setState('context', 'authors.registry');
		$this->filters['registry_id'] = new stdClass();
		$this->filters['registry_id']->list = $model_registry_id->getItems();		
		$this->filters['registry_id']->value = $model->getState("filter.registry_id");

1) With getInstance I decide the table where I want to pick up the values to build the drop-down list. In this case I used the same "authors" table from which the collections view is built. In this case the result of the query will ALWAYS be one value only, because the resulting query filters on authors.id (which is, as you pointed out, unique).
That could be anyway a useful tool to quickly scroll the list of names, alphabetically ordered, and found the desired one, without using the pagination.

2) If, instead, I use a different table, let's say the "registry" table (assuming that my "authors" table contains a registry_id column) to populate the dropdown, then I can build a query of the type "SELECT ... FROM authors as a WHERE a.registry_id=[selected id in the dropdown]". Of course I can show a different value from the numerical id, inside my drop-down (using jDom labelKey), but the value inserted in the filtering query is ALWAYS an id.
$model_archlevel = JModel::getInstance('registry', 'MantaModel');
		$model_registry->addGroupBy("a.type");
		$this->filters['registry'] = new stdClass();
		$this->filters['registry']->list = $model_registry->getItems();
		$this->filters['registry']->value = $model->getState("filter.registry");

So, I am probably missing something here, but I can't find a way to insert a value inside the filtering query other than the instance table id (which is unique in the instance table, but can occur several times inside my "authors" table as 1-n field "registry_id").

Anyhow, at the moment I am living with this, BUT, my problems are that:

A) I can't reset the filter when I select the null value (the default one with the COM_FILTER_NULL label) to cancel the filtering. A workaround is to click the "Clean/Reset" button of a Search filter, that works for both select and search filters (I have therefore inserted a Search filter inside each collection view so to achieve this scope)...anyhow this solution is not intuitive.
A strange notice: I have set up three select filters inside a collection view, and the first two filters reset properly, whereas only the last one don't :blink:
So: my single filter does not reset properly, and if I have more the one, the last one does not reset properly (although the coding is always similar).

B ) I am experiencing some troubles when trying to search on more than one table (the search filter, in its original form is EXTREMELY efficient, so, great job really!)...but that could deserve another post :-)

In any case, what about writing a deeper chapter about filters inside the guide? I volounteer to start it, eventually, although it should be checked by you (and/or others) since there are still some points I am not fully understanding (e.g. how can I send a value different from an id in the filtering query?).

Thanks for the attention

Elena
Last Edit: 12 Jun 2013 08:17 by dieda1821.
The administrator has disabled public write access.

Re: Filters - can't reset 14 Jun 2013 08:06 #7472

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
Found it!

The problem is not in filtering on the table id (although one gets one record only, but stil, it can be useful in some cases), but it was related to the syntax filter.name, that is not correct since in any case we can only send an id value. Correct is filter.id, and then the reset (inside the select filter) works properly!


Thanks in any case.

Elena
The administrator has disabled public write access.
Time to create page: 0.080 seconds

Get Started