Filter one columns with multiple values?
Filter one columns with multiple values?
Hy, i am using datatables 1.81 with mysql and i want to use fnFilter to filter on one column with 2 or more value;
I have a team of users and they have to have acces to all team clients; every users is responsible for some clients and i use fnfilter to filter on responsible column but i want the team to view somthing like in mysql where responsible=value1 or responsible=value2;
I have a team of users and they have to have acces to all team clients; every users is responsible for some clients and i use fnfilter to filter on responsible column but i want the team to view somthing like in mysql where responsible=value1 or responsible=value2;
This discussion has been closed.
Replies
1) harder, but more obvious:
you can set up your own code that looks at search values and finds a token representing "OR"
i.e. "value1|value2" and in your server script use explode('|') to turn this into an array of distinct values, then combine those values with "OR" clause in your where
2) easier, if you're comfortable with REGEX processing
Mysql has a RegExp operator (also known as RLIKE. these are not standard SQL). if you set your fnFilter to indicate regexp, you can detect that in your server script, and instead of using "responsible = value" you can compose a WHERE sub-statement using "responsible REGEXP value".
A found on forum that is enough to filter on both value to use something like
oTable.fnFilter( '44444|1234',2,true);
but is not working
http://www.datatables.net/forums/discussion/2348/fnfilter-and-regex-not-playing-nice-for-me/p1
For your first answer where i have to modify the server side php script here in $sWhere clause
$sWhere = "";
if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
{
$sWhere = "WHERE (";
for ( $i=0 ; $i
[code]
// make a copy of your original $sQuery , call it $sReturnQuery
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array(),
"sQuery" => $sReturnQuery // add query to return JSON so we can inspect it
);
[/code]