Jump to content


Multiple search conditions on flexigrid

search flexigrid

  • Please log in to reply
20 replies to this topic

#1 Kenta Saito

Kenta Saito

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts
  • LocationTokyo JAPAN

Posted 22 March 2012 - 01:04 PM

Version:
grocery_CRUD_v1.2.zip

To search with multiple conditions, I modified 3 files in grocery CRUD.

multiple.png

Form interface:
1. assets/grocery_crud/themes/flexigrid/views/list_template.php

Original:
<select name="search_field">
<input type="text" name="search_text">

Mine:
<select name="search_field[]">
<input type="text" name="search_text[]">
<select name="search_type[]"> (">=", "<"... etc. "" for 'like')
* repeat above as array.



Search engine:
2. application/libraries/grocery_crud.php

Oridinal:
$state_info->search

Mine:
$state_info->search[] (as array)


Other little things:
3. assets/grocery_crud/themes/flexigrid/js/flexigrid.js

To deal with Cookie made me confused. I turn it off this time.
Search clear button will clear all text.




Form interface:
1. assets/grocery_crud/themes/flexigrid/views/list_template.php
diff -ru --strip-trailing-cr CodeIgniter_2.1.0.orig/assets/grocery_crud/themes/flexigrid/views/list_template.php CodeIgniter_2.1.0/assets/grocery_crud/themes/flexigrid/views/list_template.php
--- CodeIgniter_2.1.0.orig/assets/grocery_crud/themes/flexigrid/views/list_template.php 2012-03-15 21:27:32.000000000 +0900
+++ CodeIgniter_2.1.0/assets/grocery_crud/themes/flexigrid/views/list_template.php 2012-03-21 14:45:12.000000000 +0900
@@ -52,13 +52,41 @@
  <form action='<?php echo $ajax_list_url?>' method='post' id='filtering_form' autocomplete = "off" >
  <div class="sDiv" id='quickSearchBox'>
   <div class="sDiv2">
-   <?php echo $this->l('list_search');?>: <input type="text" class="qsbsearch_fieldox" name="search_text" size="30" id='search_text'>
-   <select name="search_field" id="search_field">
+   <select name="search_field[]" id="search_field">
	 <option value=""><?php echo $this->l('list_search_all');?></option>
	 <?php foreach($columns as $column){?>
	 <option value="<?php echo $column->field_name?>"><?php echo $column->display_as?>&nbsp;&nbsp;</option>
	 <?php }?>
	</select>
+   <select name="search_type[]" id="search_type">
+	<option value="">like</option>
+	<option value="=">=</option>
+	<option value="&lt;&gt;">&lt;&gt;</option>
+	<option value="&lt;=">&lt;=</option>
+	<option value="&lt;">&lt;</option>
+	<option value="&gt;=">&gt;=</option>
+	<option value="&gt;">&gt;</option>
+	<option value="&lt;=&gt;">&lt;=&gt;</option>
+   </select>
+   <input type="text" class="qsbsearch_fieldox" name="search_text[]" size="30" id='search_text'>
+   <br />
+   <select name="search_field[]" id="search_field">
+	<option value=""><?php echo $this->l('list_search_all');?></option>
+	<?php foreach($columns as $column){?>
+	<option value="<?php echo $column->field_name?>"><?php echo $column->display_as?>&nbsp;&nbsp;</option>
+	<?php }?>
+   </select>
+   <select name="search_type[]" id="search_type">
+	<option value="">like</option>
+	<option value="=">=</option>
+	<option value="&lt;&gt;">&lt;&gt;</option>
+	<option value="&lt;=">&lt;=</option>
+	<option value="&lt;">&lt;</option>
+	<option value="&gt;=">&gt;=</option>
+	<option value="&gt;">&gt;</option>
+	<option value="&lt;=&gt;">&lt;=&gt;</option>
+   </select>
+   <input type="text" class="qsbsearch_fieldox" name="search_text[]" size="30" id='search_text'>
			 <input type="button" value="<?php echo $this->l('list_search');?>" id='crud_search'>
   </div>
		 <div class='search-div-clear-button'>


Search engine:
2. application/libraries/grocery_crud.php
diff -ru --strip-trailing-cr CodeIgniter_2.1.0.orig/application/libraries/grocery_crud.php CodeIgniter_2.1.0/application/libraries/grocery_crud.php
--- CodeIgniter_2.1.0.orig/application/libraries/grocery_crud.php 2012-03-15 21:27:32.000000000 +0900
+++ CodeIgniter_2.1.0/application/libraries/grocery_crud.php 2012-03-21 14:46:38.000000000 +0900
@@ -473,44 +473,88 @@
	 foreach($this->relation as $relation_name => $relation_values)
	  $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values);
  
-   if($state_info->search->field != null)
+   foreach ($state_info->search as $search)
	{
-	if(isset($temp_relation[$state_info->search->field]))
+	$fields = array();
+	if ($search->type === '')
	 {
-	 if(is_array($temp_relation[$state_info->search->field]))
-	  foreach($temp_relation[$state_info->search->field] as $search_field)
-	   $this->or_like($search_field , $state_info->search->text);
+	 if($search->field != null)
+	 {
+	  if(isset($temp_relation[$search->field]))
+	  {
+	   if(is_array($temp_relation[$search->field]))
+	   {
+		foreach($temp_relation[$search->field] as $search_field)
+		 $fields[] = $search_field;
+	   }
+	   else
+		$fields[] = $temp_relation[$search->field];
+	  }
+	  else
+	  {
+	   $fields[] = $search->field;
+	  }
+	 }
+	 else
+	 {
+	  $columns = $this->get_columns();
+	
+	  #region temporary solution for the search with relation_n_n
+	  if(!empty($this->relation_n_n))
+	   foreach($columns as $num_row => $column)
+		if(isset($this->relation_n_n[$column->field_name]))
+		 unset($columns[$num_row]);
+	  #endregion
+	
+	  foreach($columns as $column)
+	   if(isset($temp_relation[$column->field_name]))
+		if(is_array($temp_relation[$column->field_name]))
+		 foreach($temp_relation[$column->field_name] as $search_field)
+		  $fields[] = $search_field;
+		else
+		 $fields[] = $temp_relation[$column->field_name];
+	   else
+		$fields[] = $column->field_name;
+	 }
+	 if (count($fields) == 1)
+	 {
+	  $this->like($fields[0], $search->text);
+	 }
	  else
-	  $this->like($temp_relation[$state_info->search->field] , $state_info->search->text);
+	 {
+	  $this->like('concat('.implode(', " ", ', $fields).')', $search->text);
+	 }
	 }
-	else
+	else
	 {
-	 $this->like($state_info->search->field , $state_info->search->text);
+	 if($search->field != null)
+	 {
+	  if(isset($temp_relation[$search->field]))
+	  {
+	   if(is_array($temp_relation[$search->field]))
+	   {
+		foreach($temp_relation[$search->field] as $search_field)
+		 $fields[] = $search_field;
+	   }
+	   else
+		$fields[] = $temp_relation[$search->field];
+	  }
+	  else
+	  {
+	   $fields[] = $search->field;
+	  }
+
+	  if (count($fields) == 1)
+	  {
+	   $this->where($fields[0].' '.$search->type, $search->text);
+	  }
+	  else
+	  {
+	   $this->where('concat('.implode(', " ", ', $fields).')'.' '.$search->type, $search->text);
+	  }
+	 }
	 }
	}
-   else
-   {
-	$columns = $this->get_columns();
-  
-	#region temporary solution for the search with relation_n_n
-	if(!empty($this->relation_n_n))
-	 foreach($columns as $num_row => $column)
-	  if(isset($this->relation_n_n[$column->field_name]))
-	   unset($columns[$num_row]);
-	#endregion
-  
-	$search_text = $state_info->search->text;
-  
-	foreach($columns as $column)
-	 if(isset($temp_relation[$column->field_name]))
-	  if(is_array($temp_relation[$column->field_name]))
-	   foreach($temp_relation[$column->field_name] as $search_field)
-		$this->or_like($search_field, $search_text);  
-	  else
-	   $this->or_like($temp_relation[$column->field_name], $search_text);	
-	 else
-	  $this->or_like($column->field_name, $search_text);
-   }
   }
  }

@@ -2309,19 +2353,25 @@
	 {
	  $state_info->order_by = $_POST['order_by'];
	 }
-	if(!empty($_POST['search_text']))
+	if (isset($_POST['search_text']))
	 {
-	 if(empty($_POST['search_field']))
+	 for ($i = 0; $i < count($_POST['search_text']); $i++)
	  {
+	  if(!empty($_POST['search_text'][$i]))
+	  {
+	   if(empty($_POST['search_field'][$i]))
+	   {
	  
-	  $search_text = strip_tags($_POST['search_field']);
+		$search_text = strip_tags($_POST['search_field'][$i]);
	  
-	  $state_info->search = (object)array( 'field' => null , 'text' => $_POST['search_text'] );
+		$state_info->search[] = (object)array( 'field' => null , 'text' => $_POST['search_text'][$i] , 'type' => $_POST['search_type'][$i] );
	  
-	 }
-	 else
-	 {
-	  $state_info->search = (object)array( 'field' => strip_tags($_POST['search_field']) , 'text' => $_POST['search_text'] );
+	   }
+	   else
+	   {
+		$state_info->search[] = (object)array( 'field' => strip_tags($_POST['search_field'][$i]) , 'text' => $_POST['search_text'][$i] , 'type' => $_POST['search_type'][$i] );
+	   }
+	  }
	  }
	 }
	break;


Other little things:
3. assets/grocery_crud/themes/flexigrid/js/flexigrid.js
diff -ru --strip-trailing-cr CodeIgniter_2.1.0.orig/assets/grocery_crud/themes/flexigrid/js/flexigrid.js CodeIgniter_2.1.0/assets/grocery_crud/themes/flexigrid/js/flexigrid.js
--- CodeIgniter_2.1.0.orig/assets/grocery_crud/themes/flexigrid/js/flexigrid.js 2012-03-15 21:27:32.000000000 +0900
+++ CodeIgniter_2.1.0/assets/grocery_crud/themes/flexigrid/js/flexigrid.js 2012-03-21 00:04:34.000000000 +0900
@@ -41,12 +41,12 @@
	 }
   });
  
-  createCookie('crud_page_'+unique_hash,crud_page,1);
-  createCookie('per_page_'+unique_hash,$('#per_page').val(),1);
-  createCookie('hidden_ordering_'+unique_hash,$('#hidden-ordering').val(),1);
-  createCookie('hidden_sorting_'+unique_hash,$('#hidden-sorting').val(),1);
-  createCookie('search_text_'+unique_hash,$('#search_text').val(),1);
-  createCookie('search_field_'+unique_hash,$('#search_field').val(),1);
+//  createCookie('crud_page_'+unique_hash,crud_page,1);
+//  createCookie('per_page_'+unique_hash,$('#per_page').val(),1);
+//  createCookie('hidden_ordering_'+unique_hash,$('#hidden-ordering').val(),1);
+//  createCookie('hidden_sorting_'+unique_hash,$('#hidden-sorting').val(),1);
+//  createCookie('search_text_'+unique_hash,$('#search_text').val(),1);
+//  createCookie('search_field_'+unique_hash,$('#search_field').val(),1);
  
   return false;
  });
@@ -58,7 +58,8 @@

  $('#search_clear').click(function(){
   $('#crud_page').val('1');
-  $('#search_text').val('');
+  $("[name='search_text[]']").val('');
+
   $('#filtering_form').trigger('submit');
  });


Edit Signature TEST

#2 pepster

pepster

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 25 March 2012 - 10:37 PM

Thanks so much for posting! Works great.

#3 Kenta Saito

Kenta Saito

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts
  • LocationTokyo JAPAN

Posted 28 March 2012 - 04:16 AM

Hi, pepster.
Thank you for your reply !

Edit Signature TEST

#4 naufal

naufal

    Member

  • Members
  • PipPip
  • 18 posts

Posted 29 June 2012 - 06:25 AM

Hi Kenta,
would you please check this out http://gembelzillonm...g-with-example/ '.
if you can put it in GC, it will be nice :) Posted Image

#5 billakos29

billakos29

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 19 October 2012 - 07:17 PM

I have followed the previous post in order to create multiple search fields in the flexigrid. I have a column in which i store dates. As you know dates stored in mysql as Year-month-date format (etc. 2012-10-10).

User can see the format of display in the flexigrid as date/month/year with slash between the numbers (etc.10/10/2012). When somebody want to search with this format, nothing happens, but if you search with mysql format then is working. What can i do in order to search with this way?

#6 Azarudeen Ajees

Azarudeen Ajees

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 02 January 2013 - 10:05 AM

Hi,
I need the libraries file of grocery_crud.php for multiple search conditions
I really confused of your coding.
Plz send the copy of that file to my email id azarmfa@gmail.com or attach to this forum.
Thank u

#7 clustersblue

clustersblue

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 07 February 2013 - 08:01 AM

Hi Kenta,

 

Where we could download your example files?

 

Thanks

Clustersblue



#8 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 07 February 2013 - 01:27 PM

Notice To All these people that are asking to download the files in order to implement the multiple search.

The code that Kenta Saito has posted does a modification on the Grocery Crud library itself and it is specific for the version 1.2.

Even if you get these files from Kenta it is not certain that this will work as expected if you are using a newer version, like the current one 1.3.3!!!

 

In short, Kenta Saito if he wants can update his code, or even better make a library of it (or even a plugin) and distribute it.

 

For your information if you have version 1.3.3 and you select the datatables theme, it has on the header of each row a text-search field that can be used for any number of combinations of multiple searches!!!


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#9 doxrealm

doxrealm

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 11 July 2013 - 10:27 AM

I had test it with GC 1.4 BETA, and it works! 



#10 Robert

Robert

    Advanced Member

  • Members
  • PipPipPip
  • 220 posts

Posted 11 July 2013 - 12:24 PM

I need something like this to anyone was done something like this and can share it ?



#11 belllee

belllee

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 14 November 2013 - 04:19 AM



Notice To All these people that are asking to download the files in order to implement the multiple search.

The code that Kenta Saito has posted does a modification on the Grocery Crud library itself and it is specific for the version 1.2.

Even if you get these files from Kenta it is not certain that this will work as expected if you are using a newer version, like the current one 1.3.3!!!

 

In short, Kenta Saito if he wants can update his code, or even better make a library of it (or even a plugin) and distribute it.

 

For your information if you have version 1.3.3 and you select the datatables theme, it has on the header of each row a text-search field that can be used for any number of combinations of multiple searches!!!

Hi davidoster:

    I'm using grocery_crud 1.4.1 now. But, there is no multiple search in theme of flexigrid. 

    Thanks

  Best regards



#12 belllee

belllee

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 14 November 2013 - 04:29 AM



Notice To All these people that are asking to download the files in order to implement the multiple search.

The code that Kenta Saito has posted does a modification on the Grocery Crud library itself and it is specific for the version 1.2.

Even if you get these files from Kenta it is not certain that this will work as expected if you are using a newer version, like the current one 1.3.3!!!

 

In short, Kenta Saito if he wants can update his code, or even better make a library of it (or even a plugin) and distribute it.

 

For your information if you have version 1.3.3 and you select the datatables theme, it has on the header of each row a text-search field that can be used for any number of combinations of multiple searches!!!

Hi davidoster:

    I'm using grocery_crud 1.4.1 now. But, there is no multiple search in theme of flexigrid. 

    Thanks

  Best regards



#13 robitul

robitul

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 24 May 2014 - 05:17 PM

doxrealm, on 11 Jul 2013 - 17:27, said:

I had test it with GC 1.4 BETA, and it works!


Edited by robitul, 26 May 2014 - 01:11 AM.


#14 Ador El

Ador El

    Member

  • Members
  • PipPip
  • 12 posts

Posted 08 December 2014 - 10:11 PM

@doxrealm could you please post sample code. I tried modifying  assets/grocery_crud/themes/flexigrid/views/list_template.php

but then I messed up all files, and had to rollback the code because nothing was working



#15 francoross

francoross

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 13 February 2015 - 12:26 AM

How can i do dropdown list like here?

 

http://iwlearn.net/p...ocument-center/



#16 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 13 February 2015 - 02:34 AM

Well my friend... what you are looking at .. is a custom crud view. .. where 1 part .. he is displaying the regular crud.. and above the same .. its a regular CI based code that is generating the required output... Consider that as  form ... for that u need to pass extra data to the crud view. (You can search through the forums for relevant solutions.. there are many available but might be scattered in here and there)

 

Now .. once the stuff is generated, what you can do is.. use Ajax to submit controller that is generating the crud. There,..based on the parameteres recieved, you need to filter the data accordingly and there - u can re-generate the output accordingly. They are performing AJAX ... u can do it ajax way .. or avoid ajax and make form submits... to re-generate the page.. even that works out.

http://www.grocerycr...-list-view/     - this post may help you further understand the stuff better.

 

good thing... you looking at extending the possibilities..



#17 Cyn

Cyn

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 21 February 2015 - 05:02 AM

anyone tested it with 1.5 GC version?



#18 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,150 posts
  • LocationLondon

Posted 22 February 2015 - 10:41 AM

Hello All,

 

The new bootstrap theme http://www.grocerycr...ootstrap-theme/ has by default the multiple search fields and you can use it by just install it. It is a theme that I did create on my own. Here is a screenshot of how it will look like to your project:

Screen Shot 2015-02-22 at 12.33.22.png

 

This is working for grocery CRUD version 1.5 and higher so make sure that you will update grocery CRUD to the latest version first :)

 

 

 

 


Posted Image

#19 titu

titu

    Advanced Member

  • Members
  • PipPipPip
  • 43 posts

Posted 02 March 2015 - 02:23 AM

Hi web-jhonny, does this theme support edit and add forms on modals? cause on your demos they are rendered on a separete page.

 

Thanks,

Esteban



#20 ajuser

ajuser

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 29 March 2015 - 07:49 PM

Hi web-johnny, in the search fields can be used with comparison operators? For example, an attribute date, use dates between, or greater than, etc.







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users