lovasoa / SQLpage

SQL-only webapp builder, empowering data analysts to build websites and applications quickly
https://sql.datapage.app
MIT License
1.29k stars 69 forks source link

Loading Table with as default date and Searching table with a datepicker form. #76

Closed althaf004 closed 12 months ago

althaf004 commented 12 months ago

Hi I have a table with date as a column. My requirement is,

  1. When the page is initially loaded, the select query to the table has to send with a default date like today. and display results based on that query.
  2. I will have a datepicker to the top of the page, where if i needed to run the query for a different date the table has to be filled with the data of that particular date.

Is it possible to achieve this with SQLPage. I tried to check with couple of examples, but couldn't find with this requirement.

Thanks Althaf

lovasoa commented 12 months ago

I made a small example: https://replit.com/@pimaj62145/SQLPage-Time-series-example?v=1

let me know if it helps

althaf004 commented 12 months ago

will this load the data from the db based on the date selected ? because in initial load for the todays date, even though there is value, it didn't get populated.

lovasoa commented 12 months ago

Yes, look at the code!

SELECT 'list' AS component, 'Events' AS title;
SELECT event_datetime AS title,
    event_description as description,
    'calendar' as icon
FROM events
  WHERE event_datetime BETWEEN $Date AND date($Date, '+1 day');

The code is for SQLite, you'll need to adapt the syntax if you're using a different database.

althaf004 commented 12 months ago

yes i`m using postgresql.

lovasoa commented 12 months ago

You'll have to use postgres date and time functions, then.