So when I user search field on the table, wpdatatable engine search in all the fields like
SELECT field1,field2,field3 FROM table1 WHERE field1 like %xxx% OR field2 like %xxx% field3 like %xxx%.
So it makes that the result table does not make sense for the user because some time the result get match with fields that is not visible for the user.
In some case was easy to modify the mysql with the wpdatatables_filter_mysql_query hook but with other tables that has INNER JOIN and UNION is to hard.
I mean I have enable both, Column Filter and Global search. But there are 2 columns not visible ok. So when I do a search by global on the table (if I check wpdatatables_filter_mysql_query) this query make a search "like" in all columns. So my question is why? why the "global search" made a query and search the text "whatever" on the all columns table, visible columns and no visible columns?
I think, GLOBAL SEARCH should be search only on the columns that I have visible to the user, right?
There are a lot of users who wish to enable a search for all columns in the table regardless if they are visible or not.
That is why we added the option in each column which can be used to exclude certain columns from the search. By default, the function will look for all data in the table, through visible and hidden columns.
Please note that included support for the plugin does not include custom code. Using filters and hooks requires a certain level of programming skills and included support refers only to advice.
You can achieve this by turning off columns that you don't need in the search with the "Enable this column in Global Search" option in the Filtering tab of the column settings.
In the other hand, I could check when the mysql string has more that one table the global search has an issue. ex.
if I configure a table like this..
SELECT table1.f1 , table2.f2 FROM table1 INNER JOIN table2 ON ......
when you search in global search the conditional part use only the first table... I mean, it look like SELECT ...... WHERE table1.f1 LIKE %whatever% OR table1.f2 LIKE %whatever%
As you see the field f2 in (the conditional part) comes from the table2 not for the table1. So the plugin only use the first table of the SELECT
We're using a PHP SQL parser which can cause issues with JOIN, UNION, CONCAT, and sub-queries. Issues are presented as being unable to search, filter or sort the table properly.
To avoid this please prepare a MySQL view (a stored query), which will return the data that you need, call it e.g. “view1” and then build a wpDataTabled based on a simple query like “SELECT * FROM view1″.
Please note this when working with the server-side processing feature:
Please do not use “LIMIT” in the SELECT statement. wpDataTables adds it automatically and it will be overridden.
Please do not use “ORDER BY” in the SELECT statement. wpDataTables has its own sorting engine so it makes no sense to use MySQL’s sorting since it will be overridden. Also, the server-side processing feature adds this part of the statement automatically when users trigger the sorting on the front-end, and having it in the initial statement may cause the table to crash.
Only one underlying table can be edited anyway if you pass the correct selector, so you wouldn't be able to edit all data in this table, even if the search worked correctly.
Hi.
I have a table configured as
SELECT field1,field2,field3 FROM table1
field1 and field3 are not visible.
So when I user search field on the table, wpdatatable engine search in all the fields like
SELECT field1,field2,field3 FROM table1 WHERE field1 like %xxx% OR field2 like %xxx% field3 like %xxx%.
So it makes that the result table does not make sense for the user because some time the result get match with fields that is not visible for the user.
In some case was easy to modify the mysql with the wpdatatables_filter_mysql_query hook but with other tables that has INNER JOIN and UNION is to hard.
There is a easy way to do that?
Regards
Hello Alejandro
I'm not sure I understand this.
Are you using the "Text" filter for columns that are hidden from view, or are you talking about the Global Search of the table?
If you're referring to a Global Search, you can go to these two columns' settings, and disable the "Global search" check-box option:
That will exclude these columns from the search.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
I mean I have enable both, Column Filter and Global search. But there are 2 columns not visible ok. So when I do a search by global on the table (if I check wpdatatables_filter_mysql_query) this query make a search "like" in all columns. So my question is why? why the "global search" made a query and search the text "whatever" on the all columns table, visible columns and no visible columns?
I think, GLOBAL SEARCH should be search only on the columns that I have visible to the user, right?
Regards
Alejandro
Not exactly, Alejandro
There are a lot of users who wish to enable a search for all columns in the table regardless if they are visible or not.
That is why we added the option in each column which can be used to exclude certain columns from the search. By default, the function will look for all data in the table, through visible and hidden columns.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
OK I see.
Any suggestion to use any hook to filter like a $json array for only the columns that I want to filter in GLOBAL SEARCH?
I left what I'm doing if someone is interested with (for text and numeric fields)
add_filter( 'wpdatatables_filter_mysql_query', 'wpdatatables_filter_mysql_query',10,2 );
function wpdatatables_filter_mysql_query( $query, $tableId ){
switch($tableId ){
case YOUR_TABLE_ID:
if(strpos($query,"LIKE") != false){
$ini = strpos($query,"(`");
if($ini !== false){
$end = strpos($query,"')")+2;
$search = substr($query, $ini, $end - $ini);
$filterIni = strpos($query,"'%");
$filterEnd = strpos($query,"%'")+2;
$filter = substr($query, $filterIni,$filterEnd - $filterIni);
$search = array( "`table_name`.`field_1` LIKE $filter", //if the field is text
"`table_name`.`field_2` = ".str_replace("%","",$filter), //if field is numeric
"`table_name`.`field_3` LIKE $filter");
$replace = array("false" , "false" , "false");
$query = str_replace($search, $replace ,$query);
}
}
break;
}
return $query;
}
Regards
Alejandro
Hi again Alejandro
Please note that included support for the plugin does not include custom code. Using filters and hooks requires a certain level of programming skills and included support refers only to advice.
You can achieve this by turning off columns that you don't need in the search with the "Enable this column in Global Search" option in the Filtering tab of the column settings.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi Aleksandar
It is exactly what I'm looking for.
In the other hand, I could check when the mysql string has more that one table the global search has an issue. ex.
if I configure a table like this..
SELECT table1.f1 , table2.f2 FROM table1 INNER JOIN table2 ON ......
when you search in global search the conditional part use only the first table... I mean, it look like SELECT ...... WHERE table1.f1 LIKE %whatever% OR table1.f2 LIKE %whatever%
As you see the field f2 in (the conditional part) comes from the table2 not for the table1. So the plugin only use the first table of the SELECT
So the returned table is empty.
Regards
Alejandro
Hi again Alejandro
We're using a PHP SQL parser which can cause issues with JOIN, UNION, CONCAT, and sub-queries. Issues are presented as being unable to search, filter or sort the table properly.
To avoid this please prepare a MySQL view (a stored query), which will return the data that you need, call it e.g. “view1” and then build a wpDataTabled based on a simple query like “SELECT * FROM view1″.
Please note this when working with the server-side processing feature:
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi Aleksandar.
You right. But the problem is when we need to a editable table. So we must use join, union etc. in the configuration table.
Regards
Hello again Alejandro
Only one underlying table can be edited anyway if you pass the correct selector, so you wouldn't be able to edit all data in this table, even if the search worked correctly.
This is a limitation of the plugin.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables