Welcome, Guest
Username: Password: Remember me

TOPIC: Filter Options

Filter Options 14 Dec 2011 07:08 #707

  • Maujb
  • Maujb's Avatar
  • Offline
  • Junior Member
  • Posts: 27
  • Thank you received: 2
  • Karma: 2
Hi All,
I decided to summarize this post as I didn't receive any response.

I have a page with the list of Items and a combobox filter, when I select a category from the combobox it filters the items and displays only the items within the selected category.

My questions are:

1. How can I set the view to not load the items until a selection is made?

2. Can anyone help me to add a search box?
My goal is to search for an item in the selected category from the combobox. So first you select the category from the combo and then you type a name in the input.

Any help will be very much appreciated.

Thanks a lot.
Mauricio
Last Edit: 15 Dec 2011 02:15 by Maujb.
The administrator has disabled public write access.

Re: Filter Options 15 Dec 2011 05:12 #715

  • Maujb
  • Maujb's Avatar
  • Offline
  • Junior Member
  • Posts: 27
  • Thank you received: 2
  • Karma: 2
Hi Guys,
I have managed to change my view to only display the items when a selection from the combobox has being made.

I believe if you have created a view with a filter using cook, it will look pretty much like mine so I am posting here what I did in case helps someone.

I edited the default template (default.php) in the front-end

BEFORE
<form action="<?php echo(JRoute::_("index.php")); ?>" method="post" name="adminForm" class="">



	<div>
		<div class="">
			<?php echo JDom::_('html.toolbar', array(
												"bar" => $this->lists['toolbar']
												));
			?>
		</div>
		<div class="">
			<?php echo $this->loadTemplate('filters'); ?>
		</div>
		<div class="">
			<?php echo $this->loadTemplate('items'); ?>
		</div>
	</div>



	<input type="hidden" name="option" value="com_chemicalsnmaterials" />
	<input type="hidden" name="view" value="chemicals" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="filter_order" id="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" id="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
    <input type="hidden" name="layout" value="default" />
    <input type="hidden" name="Itemid" value="<?php echo JRequest::getInt('Itemid'); ?>"/>
	<input type="hidden" name="lang" value="<?php echo JRequest::getCmd('lang'); ?>"/>


	<?php echo JHTML::_( 'form.token' ); ?>


</form>


AFTER CHANGING IT
<form action="<?php echo(JRoute::_("index.php")); ?>" method="post" name="adminForm" class="">



	<div>
		<div class="">
			<?php echo JDom::_('html.toolbar', array(
												"bar" => $this->lists['toolbar']
												));
			?>
		</div>
		<div class="">
			<?php echo $this->loadTemplate('filters'); ?>
		</div>
        <?php if (($this->filters['material']->value) == '0'){?>
            <div class="">
                <p>Please choose a Material.</p>
            </div>
        <?php }else{ ?>
            <div class="">
            	<?php echo $this->loadTemplate('items'); ?>
            </div>
        <?php }?>
	</div>



	<input type="hidden" name="option" value="com_chemicalsnmaterials" />
	<input type="hidden" name="view" value="chemicals" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="filter_order" id="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" id="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
    <input type="hidden" name="layout" value="default" />
    <input type="hidden" name="Itemid" value="<?php echo JRequest::getInt('Itemid'); ?>"/>
	<input type="hidden" name="lang" value="<?php echo JRequest::getCmd('lang'); ?>"/>


	<?php echo JHTML::_( 'form.token' ); ?>


</form>

These are the line that do the trick
<?php if (($this->filters['material']->value) == '0'){?>
            <div class="">
                <p>Please choose a Material.</p>
            </div>
        <?php }else{ ?>
            <div class="">
            	<?php echo $this->loadTemplate('items'); ?>
            </div>
        <?php }?>

I hope it helps someone.

Please note that I still need to create the search box from my previous post.
2. Can anyone help me to add a search box?
My goal is to search for an item in the selected category from the combobox. So first you select the category from the combo and then you type a name in the input.

Any help will be appreciated.

Cheers
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Re: Filter Options 15 Dec 2011 08:04 #716

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
It is good coding, at the right place.

EDIT : But it should be even better if you don't load your table in memory.
What you did is only to don't see the items, but your server works for nothing.


In the VIEW.HTML.PHP file, try to make a similar check before to load your datas ;-)




Thank you Mauricio.
Coding is now a piece of cake
Last Edit: 15 Dec 2011 08:10 by admin.
The administrator has disabled public write access.

Re: Filter Options 16 Dec 2011 00:53 #719

  • Maujb
  • Maujb's Avatar
  • Offline
  • Junior Member
  • Posts: 27
  • Thank you received: 2
  • Karma: 2
Hi,
Thanks a lot for the tip.
I have done what you suggested and it works too, and as you said in a better way.

I inserted the following lines in my view.html.php
if ($this->filters['material']->value >0 ){
			$items		=& $model->getData();
	}

Not sure if it is the best way, but worked. Thanks for the great software you have created and for the support.

Do you have any idea how I can add a search input to my filter?
I noticed there are a few people after a search field to the filter. May I suggest a tutorial while this functionality is being developed?
I would do the tutorial, but I don't have that knowledge. In Fact I am going to try to implement it to my component ad if I get it to work I will post here.

Thanks
Mauricio
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Re: Filter Options 16 Dec 2011 09:03 #721

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
This is Ok if you move theses lines few lines below, AFTER the $this->filters initialization.
OR to move up, this filter initilization BEFORE theses lines you quoted.


Thank you for your post and for sharing your tips.

I really appreciate, when you try and learn by yourself. By this way you encourage people to look inside the code. If you really cannot do it or have problems, fur sure I can help, but it is always grateful to see people searching by themselves before to ask.

Karma +1
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Filter Options 17 Dec 2011 10:12 #730

  • Maujb
  • Maujb's Avatar
  • Offline
  • Junior Member
  • Posts: 27
  • Thank you received: 2
  • Karma: 2
Hi Admin,
Thanks for for the Karma point.

I have being trying with not much lucky, but won't give up yet.

Can you please tell me what files I need to modify?

I believe I need to add the input search field to the default_filters.php, which I have done. And I also believe I need to modify the function _buildQueryWhere() to include the value of the search input.

But don't know whereelse I need to do some work.

Your help will be appreciated.

Cheers
The administrator has disabled public write access.

Re: Filter Options 18 Dec 2011 05:21 #732

  • Maujb
  • Maujb's Avatar
  • Offline
  • Junior Member
  • Posts: 27
  • Thank you received: 2
  • Karma: 2
Hi Admin,
I managed to get the input search field to kind work. I opened all the files for my default view and search for lines wehre there was anything about the combobox filter (filter_material), then I duplicated most of those lines and replaced the reference to the filter_material with searchchemical (this is the id and name of my search input field).

On my models/chemicals there was a function _buildQueryWhere() , where I inserted a couple of lines as follow,
function _buildQueryWhere()
	{
		$where = array();

		$app = &JFactory::getApplication();
		$db=& JFactory::getDBO();
		$option	= JRequest::getCmd('option');
		$view	= JRequest::getCmd('view');
		$layout	= JRequest::getCmd('layout', 'default');

		$baseUserState = $option . '_' . $view . '.' . $layout . '.';

		if (isset($this->_active['filter']) && $this->_active['filter'])
		{
			$filter_material = $this->getState('filter_material');
			if ($filter_material != '')		$where[] = "_material_.id = " . (int)$filter_material . "";
			$searchchemical = $this->getState('searchchemical'); // I INSERTED THIS LINE MYSELF		
			$where[] = "a.id = " . (int)$searchchemical . ""; // I INSERTED THIS LINE MYSELF		


		}


		return parent::_buildQueryWhere($where);
	}

Now it kind work, if I select the material (category) from the combobox and type an ID of a chemical in the search field it works.
But there is where the problem is, the user won't know the chemical id and the user will type a chemical name. So I tried to change this $where[] = "a.id = " . (int)$searchchemical . ""; with $where[] = "a.title = " . (int)$searchchemical . ""; But then it doesn't work.

I need help sort this $where, I am not experienced and I think this will be hard for me to write as it also can be typed in low case, have two words.

Please help with this lines??? I think this will solve my search box.

Thanks a lot
Mauricio
The administrator has disabled public write access.

Re: Filter Options 19 Dec 2011 10:03 #734

  • Maujb
  • Maujb's Avatar
  • Offline
  • Junior Member
  • Posts: 27
  • Thank you received: 2
  • Karma: 2
Hi,
Anyone can help? Please?

I don't know how to write that query 'where' to allow me to search in the title intead of the id.

Thanks.
The administrator has disabled public write access.

Re: Filter Options 19 Dec 2011 11:18 #735

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Thank you for sharing here,

For the moment, I have to deal with important issues and new functionality developing (files and images handling).
The priority for me on the forum is for bugs and support issues.
I will help you as soon as possible for helping you writing inside your component.

But maybe this can help you :
Firstly, use the 'LIKE' keyword instead of '=' if you whant to be able to search part of a string
(searching for 'hou', to find 'house' for example)

Then, ID is integer. Title is VARCHAR.
I don't give you more clue.
I volountary don't want to give you the ready to paste solution. You should find your mistake now.

Tomorow I'll give you the answer if you don't find.
Coding is now a piece of cake
Last Edit: 19 Dec 2011 11:18 by admin.
The administrator has disabled public write access.

Re: Filter Options 19 Dec 2011 12:36 #737

  • Maujb
  • Maujb's Avatar
  • Offline
  • Junior Member
  • Posts: 27
  • Thank you received: 2
  • Karma: 2
Hi admin,
Thanks for the tips, I completely understand you are busy.
I will start to test your tips right now and let you know how I go.
Thanks a lot.
The administrator has disabled public write access.

Re: Filter Options 19 Dec 2011 12:51 #738

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I think your solution is just to correct one line. So it is not only a question of time to answer you.
If you find the answer by yourself, you learn and I think a better way to master Cook and Joomla Dev in general.

As I told you I have the answer, but it is so easy that it is an exageration if I spend my time each time fore little things such as this.

It is a pleasure to have discussion and to take lot of care for the beginners. This tool has been built to be educative too.
Important is not only the finality, but also the way to reach this finality. It helps for the future.

Good dev's and have a nice day.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Filter Options 19 Dec 2011 14:17 #740

  • Maujb
  • Maujb's Avatar
  • Offline
  • Junior Member
  • Posts: 27
  • Thank you received: 2
  • Karma: 2
Hi,
Yes, it worked!!!

I had a look at the chemicals.php in the controllers and that was follow:

$app->getUserStateFromRequest( $this->namespace . 'searchchemical', 'searchchemical', '', 'int' );

I then removed the 'int' reference, went back to the chemicals.php in the models folder

And used this lines instead of my old ones:
$searchchemical = $this->getState('searchchemical');
			$words = trim($searchchemical); //trim whitespace from the stored variable
			$where[] = "LOWER(a.title) LIKE '%$words%'";
Thanks for the tips I am very happy it worked, maybe not the best way, but does the job.

I am still looking forward to know your answer if you can, pretty sure it will be much better than my solution.

Thanks
The administrator has disabled public write access.

Re: Filter Options 19 Dec 2011 14:39 #741

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Perfect.


This was the line I was thinking about :
$where[] = "LOWER(a.title) LIKE '%$words%'";



But you did even BETTER than me, because I was forgiving this :
$app->getUserStateFromRequest( $this->namespace . 'searchchemical', 'searchchemical', '', 'int' );

Which can absolutly don't work with the 'int' type.

Thank you very much for all others users.
Coding is now a piece of cake
Last Edit: 19 Dec 2011 14:40 by admin.
The administrator has disabled public write access.

Re: Filter Options 22 Dec 2011 05:11 #751

  • Maujb
  • Maujb's Avatar
  • Offline
  • Junior Member
  • Posts: 27
  • Thank you received: 2
  • Karma: 2
Hi,
I am glad it works.
I will finish this job and I will put together a step by step on how to add the search input to the filters.

Thanks
Mauricio
The administrator has disabled public write access.
Time to create page: 0.103 seconds

Get Started