Page 1 of 1
Quick search: search for two items at the same time
Posted: 2023-10-05 09:40
by facos79
Good morning everyone, does anyone know if it is possible to search for two entries in one or more columns at the same time using quick search?
In the attached photo for example I have a table where fruit sales are stored. Each row contains the product (one fruit). I would like to search through the quick search, in the entire table, for two fruits at the same time (for example the KIWI BOERICA and KIWI SORELI). For example, if I write 'BOERICA SORELI' in the search, the search does not return any results.
I would like to use the quick search and not the detailed search
Re: Quick search: search for two items at the same time
Posted: 2023-10-05 16:41
by fdissait
Hello
Try searching : KIWI%o
You should have the 2 kiwi
% IS for any letter(s)
Re: Quick search: search for two items at the same time
Posted: 2023-10-05 18:59
by facos79
Thank you. In this case it works because they are both KIWIs but what if they were different fruits and I wanted to search for example KIWIs and APPLES? (in the table in question the apples are not present but they could be there and the user might want to search for 2 or three different products at the same time.
Can you use the quick search or do you have to use the advanced search?
Thanks for your help
Re: Quick search: search for two items at the same time
Posted: 2023-10-07 13:01
by pbottcher
Hi,
the actual answer is no, you cannot do it without adding some code. AppGini uses by default a wildcard search on the string you enter.
So if you say that you use the "space" as a delimiter for your search, you might try this:
in the hooks/TABLENAME.php -> _init function
Code: Select all
if (isset($_REQUEST['SearchString'])) {
$delimiter=' '; // change this if you want to use a different delimiter
$searchstring=$_REQUEST['SearchString'];
$QuerySearchableFields=array();
foreach($options->QueryFieldsQS as $fName => $fCaption)
if(stripos($fName, '<img') === false)
$QuerySearchableFields[$fName] = $fCaption;
$sssarray = explode($delimiter,makeSafe($searchstring)); // safe search stringarray
$options->QueryWhere = $options->QueryWhere ? $options->QueryWhere : " WHERE 1=1 ";
$s=array();
foreach($sssarray as $idx => $sss) {
if(count($QuerySearchableFields))
$s[]=implode(
" LIKE '%{$sss}%' OR ",
array_keys($QuerySearchableFields)
) . " LIKE '%{$sss}%'";
}
$options->QueryWhere.='AND ('.implode(' OR ',$s).' )';
$_REQUEST['NewSearch']=$searchstring;
$_REQUEST['SearchString']='';
}
In the _header function you need to add to the tableview case:
Code: Select all
if (isset($_REQUEST['NewSearch'])) {
$search=$_REQUEST['NewSearch'];
$header='<%%HEADER%%><script>$j(function() {$j("#SearchString").val("'.$search.'");$j(".table-responsive td:not([colspan])").mark("' . html_attr($$search) . '", { className: "text-bold bg-warning", diacritics: false, separateWordSearch: 1 });})</script>';
}
Re: Quick search: search for two items at the same time
Posted: 2023-10-10 18:34
by facos79
Thanks for your help. I'll try to follow your advice this week. Thank you
Re: Quick search: search for two items at the same time
Posted: 2023-10-15 13:49
by facos79
error:
Fatal error: Uncaught Error: Attempt to assign property "QueryWhere" on null in /data/vhosts/........../hooks/Movimenti_acquisto_peso.php:117 Stack trace: #0 /data/vhosts/......../Movimenti_acquisto_peso_view.php(259): Movimenti_acquisto_peso_header() #1 {main} thrown in /data/vhosts/........./hooks/Movimenti_acquisto_peso.php on line 117
Re: Quick search: search for two items at the same time
Posted: 2023-10-15 15:24
by pbottcher
Can you post your code here?
Re: Quick search: search for two items at the same time
Posted: 2023-10-15 15:37
by facos79
what code do you need? I entered the code you posted. If you need more info I can send what you need. Thank you
Re: Quick search: search for two items at the same time
Posted: 2023-10-15 15:56
by pbottcher
Can you show the _init function with the code and the _header -> tableview case as mentioned above.
Re: Quick search: search for two items at the same time
Posted: 2023-11-26 13:54
by facos79
Thanks, I tried again. The filter works but just add the code in the hook file of the corresponding table:
Code: Select all
if (isset($_REQUEST['SearchString'])) {
$delimiter=' '; // change this if you want to use a different delimiter
$searchstring=$_REQUEST['SearchString'];
$QuerySearchableFields=array();
foreach($options->QueryFieldsQS as $fName => $fCaption)
if(stripos($fName, '<img') === false)
$QuerySearchableFields[$fName] = $fCaption;
$sssarray = explode($delimiter,makeSafe($searchstring)); // safe search stringarray
$options->QueryWhere = $options->QueryWhere ? $options->QueryWhere : " WHERE 1=1 ";
$s=array();
foreach($sssarray as $idx => $sss) {
if(count($QuerySearchableFields))
$s[]=implode(
" LIKE '%{$sss}%' OR ",
array_keys($QuerySearchableFields)
) . " LIKE '%{$sss}%'";
}
$options->QueryWhere.='AND ('.implode(' OR ',$s).' )';
$_REQUEST['NewSearch']=$searchstring;
$_REQUEST['SearchString']='';
}
You don't need to add the other part of code.