Hi!
I am trying to implement a HubDB row filter using and a pagination of the the same HubDB table.
I have tried using the select option to filter the rows based on specific properties of the row, but it doesn’t seem to work with my pagination code. I am hoping someone can point me in the right direction on how to combine the filteration and pagination together.
Below is my pagination code:
{% set batch_num = 2 %}
{% if not request.query_dict.page_num %}
{% set page_num = 1 %}
{% set offset_num = 0 %}
{% elif request.query_dict.page_num %}
{% set page_num = request.query_dict.page_num %}
{% set offset_num = page_num|add(-1) * batch_num %}
{% endif %}
{% set query = “limit=” ~ batch_num ~ “&offset=” ~ offset_num %}
{% set rows = hubdb_table_rows(‘XXXXXXX’, query) %}
<ul class=“item-list”>
{% for row in rows %}
<li class=“list-item”>{{ row[“type”].name }}</li>
{% endfor %}
</ul>
{% set nav = hubdb_table_rows(‘XXXXXXX’) %}
{% set total_pages = nav|length|divide(batch_num) %}
{% set more_pages = total_pages - page_num %}
<nav>
{% if page_num > 1 %}
<a class=“previous-posts-link” href=“{{ content.absolute_url }}?page_num={{ page_num|add(-1) }}” title=“Next”>Next</a>
{% endif %}
{% if more_pages == 0 %}
{% if page_num|add(-4) >= 1 -%} <a href=“{{ content.absolute_url }}?page_num={{ page_num|add(-4) }}”>{{ page_num|add(-4) }}</a>{%- endif %}
{% endif %}
{% if more_pages <= 1 %}
{% if page_num|add(-3) >= 1 %}<a href=“{{ content.absolute_url }}?page_num={{ page_num|add(-3) }}”>{{ page_num|add(-3) }}</a>{% endif %}
{% endif %}
{% if page_num|add(-2) >= 1 %} <a href=“{{ content.absolute_url }}?page_num={{ page_num|add(-2) }}”>{{ page_num|add(-2) }}</a>{% endif %}
{% if page_num|add(-1) >= 1 %}<a href=“{{ content.absolute_url }}?page_num={{ page_num|add(-1) }}”>{{ page_num|add(-1) }}</a>{% endif %}
<a class=“active” href=“{{ content.absolute_url }}?page_num={{ page_num }}”>{{ page_num }}</a>
{% if page_num|add(1) <= total_pages %}<a href=“{{ content.absolute_url }}?page_num={{ page_num|add(1) }}”>{{ page_num|add(1) }}</a>{% endif %}
{% if page_num|add(2) <= total_pages %}<a href=“{{ content.absolute_url }}?page_num={{ page_num|add(2) }}”>{{ page_num|add(2) }}</a>{% endif %}
{% if page_num <= 2 %}
{% if page_num|add(3) <= total_pages %}<a href=“{{ content.absolute_url }}?page_num={{ page_num|add(3) }}”>{{ page_num|add(3) }}</a>{% endif %}
{% endif %}
{% if page_num == 1 %}
{% if page_num|add(4) <= total_pages %}<a href=“{{ content.absolute_url }}?page_num={{ page_num|add(4) }}”>{{ page_num|add(4) }}</a>{% endif %}
{% endif %}
{% if total_pages > page_num %}
<a class=“next-posts-link” href=“{{ content.absolute_url }}?page_num={{ page_num|add(1) }}” title=“Older Posts”>Previous</a>
{% endif %}
</nav>