Oct 23, 20204:16 AM - edited Oct 28, 202011:12 AM
Contributor | Platinum Partner
Filtering HubDB as button
Hi,
I just created and succesfully printed out the results wanted for several tables on my website, but I'm struggling in creating a filtering elements to filter the date (years more specifically), of the single rows.
Basically I would need something like this:
(this from the live environment, which I should migrate)
But when it comes to trying to append filter in GET, managing the Url which I attach as follows:
Nothing happens: what am I missing: I basically would need to create a way to filter out the results (a module to be used in different pages would be great).
Thx for any answer or suggestion you may provide me.
{% set table_info = module.hubdbtable_field %}
{% set from = "2019-06-05T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp %}
{% set to = "2021-03-11T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp %}
{% set queryparam = "published_date__gt="+ from +"&published_date__lt="+to %}
{% for row in hubdb_table_rows(table_info, queryparam) %}
<div>
<span>{{row.published_date|datetimeformat('%B %e, %Y')}}</span>
</div>
{% endfor %}
Result is: November 6, 2020
Additional Helper: If you need the filter from the URL, you can use the request.query_dict object. But take care of a fallback or handle it otherwise. Also the filters: minus_time() and plus_time() may be helpful: