I have a table named usersTable. Its Data attribute is set to {{ customers.data }} I need to change this Data attribute to different query if the search text field contains some string (its for search by phone number when I need to run a different query and show the result in the usersTable).
Hey @ckissi! You can definitely do this using plain Javascript. Use the Ternary Operator to evaluate a boolean condition related to your search text field. So letβs say we have a textinput (textinput1) two queries β query1 and query2 β and we want our table (table1) to show query1.data if textinput1 contains the β555-555-5555β. Weβd use this JS in the βdataβ attribute of our table:
Based on how detailed you want to get, you can use other JS functions to pattern match for your string or phone number. BTW, moving this into the βHow Do Iβ category.
Hi,
I'm trying to implement this with table data source depending on temporary state boolean value: {{ temporaryStateBoolean ? query1.data : query2.data }}
but the table's contents stay the same regardless of temporary state's value.
Can you advise me on what could be the problem here?
Best,
Jacek
@justin - This is super helpful and I'm using it quite a bit. Do you have a recommendation on how to handle this when there could be around 15 possible tables?
Basically depending on the user input in a dropdown, then a different query needs to execute and show the output in the table.
I worry that if I do it the following way then it'll make the app slow and heavy (only showing 3 tables for the example):
{{ select1.value.includes("us") ? settl_us.data :
select1.value.includes("ca") ? settl_ca.data : settl_uk.data
}}
You probably want to use a transformer or JS query here and apply a switch-case control and return the table you want. You can then use {{jsSwitchQuery.data}} or {{transformerSwitch.data}} as your table's data source.
Hi @Tanguy, another option I can think of is using switch in your JS Query resource:
const country = select1.value
switch(country) {
case "US":
referral_fees_us.trigger();
break;
case "CA":
referral_fees_us.trigger();
break;
...
default:
break;
}
And use another JS Query that has the same format as above but instead of trigger, you are returning the data of those country specific query, say for example dataToShowJSQuery:
const country = select1.value
switch(country) {
case "US":
return referral_fees_us.data;
case "CA":
return referral_fees_us.data;
...
default:
return []
}
What you use in the data source section of the table would be dataToShowJSQuery.data.