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
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