Buy Now
Sign in

Advanced read data Function with filter from function

Proximate , August 17 2018, 09:50
P
Proximate 110
August 17 2018, 09:50 #379647
Hi
For a Filter in a select function i need some kind of logic.
Actually the (Hardcoded) Filter looks somethin like that:
year_id:{data:Data.year}
AND
(
home:1
OR
visitor:1
)
This results in a fixed scenario where a table is displayed with the games where team 1 is either the visitor or home team.
Now i've got a select Form on this page where the user can select (dropdown not multiple): Home, Visitor, Both (Home and Visitor Matches)
based on this selection the Query should change to:
// Scenario Visitor:
year_id:{data:Data.year}
AND visitor=1
// Scenario Home:
year_id:{data:Data.year}
AND home=1
So at least form the 2nd Line i have to use a Switch - but if i try to call a switch-function ({fn:xyz}) or my following switch statement (which returns value as VAR / or not both tried) the Query failes --> Undefined column {fn:xyz} or {var:xyz} - is it generally possible to call a fn inside a Filter?
To bring it all together here is my Custom Code for the switch statement (which is also not working) - same error.
switch({data:Data.location}){
case 'home':
$query_string = ' AND home:{data:Data.team}';
break;
case 'visitor':
$query_string = ' AND visitor:{data:Data.team}';
break;
case 'both':
default:
$query_string = ' AND ( home:{data:Data.team} OR visitor:{data:Data.team} )';
}

return $query_string;
Bildschirmfoto_2018-08-17_um_11.49.07.png
I don't want to create the whole read_data function three times just because of a single line...
thanks for your input
S
simelas 173
September 17 2018, 21:23 #380228
Hi Proximate,
from where is coming the value of your Data.year ? Form selector or read data function? e.g. read_years
{data:Data.year}