I'm new to Retool but am really liking what I've been able to accomplish so far. One of the remaining items that I can't seem to figure out is how to apply a date picker to values in a table that is being pulled from a Rest API query. I'd like to format it like below, where the user can select the past 30, 60, or 90 days of data. Is that possible? Thanks!
You would have to pass in the selected value to your api using something like
moment().subtract('month', 1).startOf('month')
moment().subtract('month', 1).endOf('month')
This would be for 30 days the last month 30 day period (July 1 - July 31
Your API would have to read the value and send back the data for the last 30 days
Also, you can use days instead of month, etc.
Check out: Moment.js | Docs
Thanks! I'll take a look at that. The API I'm using does not have the ability to pass a date range along. I'm thinking I may need to create a Query JSON with SQL resource but having trouble figuring out what that would look like.
select * from {{formatDataAsArray(yourTable.data)}} where {{yourDaysfield.value}} = leaseLastDate.value
Not seeing the table or any code or JSON from the table, it's difficult for me to say how to approach this. For example, you may not need formatDataAsArray....
table1 will always be populated with query2.data initially so the value there won't change.
Create a temporary state. Name it state1 (by default)and give it the default value of query2.data
The reason for doing this is so you can query the temp state to then make the table view change when you select 30, 60, or 90.
Then write another query changeTheDate select * from {{formatDataAsArray(state1.value)}} where {{leaseLastDate.value}} = {{leaseLastDate.value}} - {{moment.subtract(yourDaysSelectedField.value, "days")}}
When selecting the 30, 60, or 90 field, add an event handler on that select field (On Change) and trigger changeTheDate query.
Then take that result of that query (as in below) and do the following in the Success event handler
select component table 1 and then select set Data and add changeTheDate.data
Thanks! That is extremely helpful. I'm getting closer but still running into an issue. As written in the query, I'm getting a leaselastdate.value is not defined. The only way I can seem to pull that up is with the following:
However, that seems to be pulling an individual record. Is that correct?
Using table1.data['1'].leaseLastDate should not be necessary as you are searching that data set for where any leaseLastDate is equal to the current date - 30 days .... using the ['1'] is why you are only getting one record back. - you want all dates from 30 days ago