⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Multiple search conditions on flexigrid



Kenta Saito
  • profile picture
  • Member

Posted 22 March 2012 - 13:04 PM

Version:
grocery_CRUD_v1.2.zip

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

[attachment=78:multiple.png]

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

[indent=1]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.[/indent]


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

[indent=1]Oridinal:
$state_info->search

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

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

[indent=1]To deal with Cookie made me confused. I turn it off this time.
Search clear button will clear all text.[/indent]



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');
});

pepster
  • profile picture
  • Member

Posted 25 March 2012 - 22:37 PM

Thanks so much for posting! Works great.

Kenta Saito
  • profile picture
  • Member

Posted 28 March 2012 - 04:16 AM

Hi, pepster.
Thank you for your reply !

naufal
  • profile picture
  • Member

Posted 29 June 2012 - 06:25 AM

Hi Kenta,
would you please check this out http://gembelzillonmendonk.wordpress.com/2010/06/28/flexigrid-and-codeigniter-with-advanced-searching-with-example/ '.
if you can put it in GC, it will be nice :) [img]http://gembelzillonmendonk.files.wordpress.com/2010/06/flexigrid.png[/img]

billakos29
  • profile picture
  • Member

Posted 19 October 2012 - 19: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?

Azarudeen Ajees
  • profile picture
  • Member

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

clustersblue
  • profile picture
  • Member

Posted 07 February 2013 - 08:01 AM

Hi Kenta,

 

Where we could download your example files?

 

Thanks

Clustersblue


davidoster
  • profile picture
  • Member

Posted 07 February 2013 - 13:27 PM

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

The code that [member='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, [member='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!!!


doxrealm
  • profile picture
  • Member

Posted 11 July 2013 - 10:27 AM

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


Robert
  • profile picture
  • Member

Posted 11 July 2013 - 12:24 PM

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


belllee
  • profile picture
  • Member

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 [member='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, [member='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


belllee
  • profile picture
  • Member

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 [member='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, [member='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


robitul
  • profile picture
  • Member

Posted 24 May 2014 - 17:17 PM

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

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


Ador El
  • profile picture
  • Member

Posted 08 December 2014 - 22: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


francoross
  • profile picture
  • Member

Posted 13 February 2015 - 00:26 AM

How can i do dropdown list like here?

 

http://iwlearn.net/publications/document-center/


Amit Shah
  • profile picture
  • Member

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.

/topic/2278-how-to-add-search-filter-between-two-date-in-list-view/     - this post may help you further understand the stuff better.

 

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


Cyn
  • profile picture
  • Member

Posted 21 February 2015 - 05:02 AM

anyone tested it with 1.5 GC version?


web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 22 February 2015 - 10:41 AM

Hello All,

 

The new bootstrap theme http://www.grocerycrud.com/bootstrap-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:

[attachment=905: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 :)

 

 

 

 


titu
  • profile picture
  • Member

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


ajuser
  • profile picture
  • Member

Posted 29 March 2015 - 19: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.