Estate Agent example - add custom 'order by'

Hi I’ve been trying out the estate agent

example: GitHub - HubSpot/cms-custom-objects-example · GitHub

I’ve got it working, however I want to adjust the order the items are displayed for example by bedrooms. Any idea how this is done?

Hi @ben-duchy, you can use the orderBy property to order items:

{% set queryparam = queryparam ~ '&orderBy=[bedrooms field]' %}{% for row in hubdb_table_rows('[id]', queryparam) %}{% endfor %}

If you want to reverse the order use a minus sign before the field name like so:

{% set queryparam = queryparam ~ '&orderBy=-[bedrooms field]' %}

@piersg Is there a way to load the page with a pre-selected option? Currenlty the page starts with ‘show all’ but I want to remove this and start it with the 3rd item in the list.

Perfect, thanks @piersg :+1:

@ben-duchy, when you say ‘show-all’ do you mean you have a select/dropdown list that is being used to filter the DB and you want to change the default option of that list? What are the items in that list that you’re using to filter? The number of bedrooms?

Hi @piersg thanks for coming back to me on this.
Yes thats correct, the select list is being used to display different data, namely the different housing developments my employer has built for example London, Manchester, Leeds etc. As theres too much data to pull through (558 rows and growing), I want to remove the ‘show all’ from the list and start the original page load on a different option.

I’m aware I can remove the ‘Show All’ by simply commenting it out, but the page still shows everything when the page is loaded. I would ideally like to show another option by default.

<form id=“filter” method=“get”>
<select name=“type” form=“filter” onChange=“this.form.submit()”>
<option value=“show-all”>Show All</option>
{% set types = hubdb_table_column(123456789, “type”).options %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list%}
{% if choice.id == request.query_dict.type%}
<option selected=“selected” value=“{{ choice.id }}”>{{ choice.name }}</option>
{% else %}
<option value=“{{ choice.id }}”>{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
<input id=“submit-button” type=“submit” value=“search”>
</form>