Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] Multiple search filters on same list view

Multiple search filters on same list view 06 Sep 2013 20:30 #11017

  • Tomaselli
  • Tomaselli's Avatar
  • Online
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
Multiple search text filters on the same view are not correctly generated.

in the UI view they seems generated, because there are the input fields but in the code is only ONE search (apparently the last).
Moreover if an "instance name" and/or a label is configured in the builder for the said filters, in the code there is no track of it.
So apparently these things are completely missing from the generated code.


UPDATE:
some more details about what is generated and it isn't.
Assuming we have 3 search filters and we gave them a label and an instance name in the builder, respectively: keyword, make, model

we have the following in the generated component:

ROOT\components\com_MYCOMPONENT\views\MYITEMS\view.html.php:
code generated is
		//Filters
		// Keyword
		$filters['search_search']->jdomOptions = array(
			'dataValue' => $state->get('search.search')
		);

		// Make
		$filters['search_search']->jdomOptions = array(
			'dataValue' => $state->get('search.search')
		);

		// Model
		$filters['search_search']->jdomOptions = array(
			'dataValue' => $state->get('search.search')
		);

it should be
		//Filters
		// Keyword
		$filters['search_keyword']->jdomOptions = array(
			'dataValue' => $state->get('search.keyword')
		);

		// Make
		$filters['search_make']->jdomOptions = array(
			'dataValue' => $state->get('search.make')
		);

		// Model
		$filters['search_model']->jdomOptions = array(
			'dataValue' => $state->get('search.model')
		);

file ROOT\components\com_MYCOMPONENT\views\MYITEMS\tmpl\default.php:
code generated
			<div class="pull-right">
				<?php echo $this->filters['search_search']->input;?>
			</div>
			<div class="pull-right">
				<?php echo $this->filters['search_search']->input;?>
			</div>
			<div class="pull-right">
				<?php echo $this->filters['search_search']->input;?>
			</div>

it should be
			<div class="pull-right">
				<!-- MISSING LABEL FOR "KEYWORD" !?!?!? WHERE IS IT? -->
				<?php echo $this->filters['search_keyword']->input;?>
			</div>
			<div class="pull-right">
				<!-- MISSING LABEL FOR "MAKE" !?!?!? WHERE IS IT? -->
				<?php echo $this->filters['search_make']->input;?>
			</div>
			<div class="pull-right">
				<!-- MISSING LABEL FOR "MODEL"!?!?!? WHERE IS IT? -->
				<?php echo $this->filters['search_model']->input;?>
			</div>

file ROOT\components\com_MYCOMPONENT\models\MYITEMS.php:
in the public function __construct we have
		//Define the searchable fields
		$this->set('search_vars', array(
			'search' => 'string'
				));

it should be
		//Define the searchable fields
		$this->set('search_vars', array(
			'keyword' => 'string',
			'make' => 'string',
			'model' => 'string'
				));

in the same file but on protected function prepareQuery we ONLY have (apparently it seems the last instance)
		//WHERE - SEARCH : search_search : search on Model
		$search_search = $this->getState('search.search');
		$this->addSearch('search', 'a.model', 'like');
		if (($search_search != '') && ($search_search_val = $this->buildSearch('search', $search_search)))
			$this->addWhere($search_search_val);

it should be
		//WHERE - SEARCH : search_keyword : search on Model
		$search_keyword = $this->getState('search.keyword');
		$this->addSearch('keyword', 'a.keyword', 'like');
		if (($search_keyword != '') && ($search_keyword_val = $this->buildSearch('keyword', $search_keyword)))
			$this->addWhere($search_keyword_val);

		//WHERE - SEARCH : search_make : search on Make
		$search_make = $this->getState('search.make');
		$this->addSearch('make', 'a.make', 'like');
		if (($search_make != '') && ($search_make_val = $this->buildSearch('make', $search_make)))
			$this->addWhere($search_make_val);

		//WHERE - SEARCH : search_model : search on Model
		$search_model = $this->getState('search.model');
		$this->addSearch('model', 'a.model', 'like');
		if (($search_model != '') && ($search_model_val = $this->buildSearch('model', $search_model)))
			$this->addWhere($search_model_val);

on file ROOT\components\com_MYCOMPONENT\models\forms\MYITEM.xml
we have:
		<field name="search_search"
				type="cksearch"
				placeholder="MYCOMPONENT_FILTER_NULL_KEYWORD"
				label="MYCOMPONENT_JSEARCH_KEYWORD"
				class="element-search search-query"
				ui="chosen"/>				
				
		<field name="search_search"
				type="cksearch"
				placeholder="MYCOMPONENT_FILTER_NULL_MAKE"
				label="MYCOMPONENT_JSEARCH_MAKE"
				class="element-search search-query"
				ui="chosen"/>

		<field name="search_search"
				type="cksearch"
				placeholder="MYCOMPONENT_FILTER_NULL_MODEL"
				label="MYCOMPONENT_JSEARCH_MODEL"
				class="element-search search-query"
				ui="chosen"/>

it should be
		<field name="search_keyword"
				type="cksearch"
				placeholder="MYCOMPONENT_FILTER_NULL_KEYWORD"
				label="MYCOMPONENT_JSEARCH_KEYWORD"
				class="element-search search-query"
				ui="chosen"/>				
				
		<field name="search_make"
				type="cksearch"
				placeholder="MYCOMPONENT_FILTER_NULL_MAKE"
				label="MYCOMPONENT_JSEARCH_MAKE"
				class="element-search search-query"
				ui="chosen"/>

		<field name="search_model"
				type="cksearch"
				placeholder="MYCOMPONENT_FILTER_NULL_MODEL"
				label="MYCOMPONENT_JSEARCH_MODEL"
				class="element-search search-query"
				ui="chosen"/>

this is not tested yet on my component, so I apologize in advance if there is a mistake, I'll give more details when I'll have.
Last Edit: 06 Sep 2013 21:24 by Tomaselli.
The administrator has disabled public write access.

Multiple search filters on same list view 07 Sep 2013 17:51 #11023

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
This was working before.

Will have a look.
About the labels, they are now inside the placeholder.
Coding is now a piece of cake
The administrator has disabled public write access.

Multiple search filters on same list view 08 Sep 2013 11:36 #11026

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

I confirm that I have the same behaviour when using 2 'Search Filter' on 2 different Tables ...
- First on the Name, second on Year of Birth -

The administrator has disabled public write access.

Multiple search filters on same list view 23 Sep 2013 18:08 #11157

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Fixed since 2.6
www.j-cook.pro/index.php/docs/versions/121-2-6

Also some code is now useless in the view file :
$search_keyword = $this->getState('search.xxxxx');
Is populated automatically now as well as the others filters. Cook is reusing the JForm classes to make filters working the same way...
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.067 seconds

Get Started