I want to do dropdown feature and based on selection the table reflects using mysql query

Hi can you please help me tackle this problem
here is my query:
SELECT
transaction_version AS txnVersion,
txn_id AS txnId,
organization AS org,
data_source AS dataSource,
user_id AS userId,
order_type AS orderType,
transaction_amount AS txnAmount,
status AS txnStatus,
status_reference AS statusRef,
timeline AS txnTimeline,
order_timestamp AS orderTimestamp,
event_timestamp AS eventTimestamp,
payment_details AS paymentDetails,
fulfilment_details AS fulfilmentDetails,
refund_details AS refundDetails,
campaign_details AS campaignDetails,
bank_transaction_details AS bankTransactionDetails,
created_on AS createdOn,
last_updated_on AS lastUpdatedOn
FROM
transactions
WHERE
{{ !dropdownButton.value }} OR
status LIKE CONCAT('%', {{ dropdownButton.value }}, '%');

Create an event handler for "change" of the dropdown and trigger the query that feeds the table.

Also, not sure why this is needed LIKE CONCAT('%', {{ dropdownButton.value }}, '%'); if the status in the database are IN_THIS_FORMAT then just match on that, or are you trying to do a fuzzy match/search?

1 Like

I want to display table on the basis of dropdown item(status) selected.
I did event handler but not working.

image

does "getDataFromDropdown" return the database results and is the datasource for the table?

for example I have a query get_user_list, it is manually triggered, and the table uses that query as the datasource. Then the button, that will have the click handler to trigger get_user_list.

This is throwing me off though...
WHERE {{ !dropdownButton.value }} OR
status LIKE CONCAT('%', {{ dropdownButton.value }}, '%');

so if you pick PAYMENT_SUCCESS then won't that SQL be:
WHERE !PAYMENT_SUCCESS OR
status LIKE CONCAT('%PAYMENT_SUCCESS%');? is that valid?

Shouldn't the condition just be WHERE status = {{ dropdownButton.value }}?

another question, what is feeding that select list? Are there supposed to be duplicates?

By default I need to show whole table.
when no value is selected , and actually I am new in retool and I am stuck here from few days, so need help on this

If you have to load the whole list on page load, then there is no reason for a second query with less results. You could make a code query or even a transformer to get filtered data.

image

Or maybe try using a table filter tied to the status column and your dropdown?

Still not able to filter my table based on the drop down button selection item list,
can you please tell me step by step process so that I can perform this, based on my query.
As I am new in retool not able to this.

Thanks

And also while doing {{dropdownButton.value}} getting undefined

I just investigated for you real quick and check it out.... (I didn't know either)
image

Dropdown Buttons don't have a value they seem to just be event initiators based on the item clicked. You might want to use a regular select since they retain their value when changed.

Here is a minimal example using select.
table-filter-example.json (70.2 KB)