CMS Development

barbaramae
Member

HubDB: orderBy using a select menu

I have a page set up showing results from a HubDB. I'd like to let the user sort the results by different columns. So far I have the following code, but can't figure out how to attach the selected option to my queryparameter.

 

Code to capture the user's sort selection:

<select class="sortorder" name="orderBy" form="form_id" onchange="this.form.submit()">
<option selected="" value="">Featured</option>
<option value="deadline">Deadline</option>
<option value="scholarship_name">Name</option>
</select>

 

Current QueryParameter

{% set queryparam = "" %}

{% if request.query_dict.field_of_study in ["1", "2", "3", "4", "5", "6", "7"] %}
{% set queryparam = queryparam ~ "&field_of_study__contains="~request.query_dict.field_of_study|urlencode %}
{% endif %}

1 Reply 1
TRooInbound
Key Advisor

HubDB: orderBy using a select menu

Hi @barbaramae

 

 

you need to append further parameter for order items to query string

{% if request.query_dict.field_of_study in ["1", "2", "3", "4", "5", "6", "7"] %}
{% set queryparam = queryparam ~ "&field_of_study__contains="~request.query_dict.field_of_study|urlencode %}
{% endif %}

/* code for the sort item */
{% if request.query_dict.sortorder in ["Featured", "Deadline", "Name"] %}
    {% set queryparam = queryparam ~ "&orderBy=" ~ request.query_dict.sortorder %}
{% endif %}

No need to add follow line as it reset your parameter on reload page

{% set queryparam = "" %}

Hope its help to solve your query 🙂

 

Did our post help answer your query? Help the Community by marking it as a solution.

Team TRooInbound

 

For more information please visit our website or mail us at hello@trooinbound.com

0 Upvotes