Custom module collection won't sort by field other than weighting

I need the output of a custom module to be sorted differently in different places. I can change the order by changing from sorting by weighting DESC to ASC. But sorting by my custom weighting field doesn’t have an effect. Any help appreciated.
The module insertion. Note HomeWeighting is a number field type:

{% component source: "Program", layout: "List Home", sortBy: "HomeWeighting", sortOrder: "DESC", object: "collection", collectionVariable: "program", type: "module" %}

The layout:

<section class="home-program">
    <h1 class="home-program-title">Our Programs</h1>
    <div class="home-program__wrapper">
        {% comment %}First item is featured {% endcomment %}
        <div class="home-program__items-wrapper home-program__items-wrapper--featured">
            {% for program in this.items limit:1  %}
            {% comment %}Select item color based on condition {% endcomment %}
            
            {% if program['Condition'] == 'hypertrophic cardiomyopathy' %}
            {% assign color = 'red' %}
            {% elsif program['Condition'] == 'diastolic heart failure' %}
            {% assign color = 'teal' %}
            {% elsif program['Condition'] == 'systolic heart failure' %}
            {% assign color = 'blue' %}
            {% endif %}

            <div class="home-program__item home-program__item--{{color}}">
            <h2 class="home-program__title">{{program['Name']}}</h2>

            {% if program['SubIndication1'] != '' and program['SubIndication1'] != null %}
            <h3 class="home-program__subindication">{{program['SubIndication1']}}</h3>
            {% assign percentOfPhase = program['SubIndication1PhaseComplete'] | plus: 0 | divided_by: 4 %}
            {% if program['SubIndication1Phase'] == 'Preclinical' %}
            {% assign percentComplete = 1 | plus: percentOfPhase %}
            {% elsif program['SubIndication1Phase'] == 'Phase 1' %}
            {% assign percentComplete = 25 | plus: percentOfPhase %}
            {% elsif program['SubIndication1Phase'] == 'Phase 2' %}
            {% assign percentComplete = 50 | plus: percentOfPhase %}
            {% elsif program['SubIndication1Phase'] == 'Phase 3' %}
            {% assign percentComplete = 75 | plus: percentOfPhase %}
            {% endif %}
            <div class="home-program__progress" style="width:{{percentComplete}}%"></div>
            <p class="home-program__phase">{{program['SubIndication1Phase']}}</p>
            {% endif%}
            
            {% if program['SubIndication2'] != '' and program['SubIndication2'] != null %}
            <h3 class="home-program__subindication">{{program['SubIndication2']}}</h3>
            {% assign percentOfPhase = program['SubIndication2PhaseComplete'] | plus: 0 | divided_by: 4 %}
            {% if program['SubIndication2Phase'] == 'Preclinical' %}
            {% assign percentComplete = 1 | plus: percentOfPhase %}
            {% elsif program['SubIndication2Phase'] == 'Phase 1' %}
            {% assign percentComplete = 25 | plus: percentOfPhase %}
            {% elsif program['SubIndication2Phase'] == 'Phase 2' %}
            {% assign percentComplete = 50 | plus: percentOfPhase %}
            {% elsif program['SubIndication2Phase'] == 'Phase 3' %}
            {% assign percentComplete = 75 | plus: percentOfPhase %}
            {% endif %}
            <div class="home-program__progress" style="width:{{percentComplete}}%"></div>
            <p class="home-program__phase">{{program['SubIndication2Phase']}}</p>
            {% endif%}

            {% if program['SubIndication3'] != '' and program['SubIndication3'] != null %}
            <h3 class="home-program__subindication">{{program['SubIndication3']}}</h3>
            {% assign percentOfPhase = program['SubIndication3PhaseComplete'] | plus: 0 | divided_by: 4 %}
            {% if program['SubIndication3Phase'] == 'Preclinical' %}
            {% assign percentComplete = 1 | plus: percentOfPhase %}
            {% elsif program['SubIndication3Phase'] == 'Phase 1' %}
            {% assign percentComplete = 25 | plus: percentOfPhase %}
            {% elsif program['SubIndication3Phase'] == 'Phase 2' %}
            {% assign percentComplete = 50 | plus: percentOfPhase %}
            {% elsif program['SubIndication3Phase'] == 'Phase 3' %}
            {% assign percentComplete = 75 | plus: percentOfPhase %}
            {% endif %}
            <div class="home-program__progress" style="width:{{percentComplete}}%"></div>
            <p class="home-program__phase">{{program['SubIndication3Phase']}}</p>
            {% endif%}

            {% if program['SubIndication4'] != '' and program['SubIndication4'] != null %}
            <h3 class="home-program__subindication">{{program['SubIndication4']}}</h3>
            {% assign percentOfPhase = program['SubIndication4PhaseComplete'] | plus: 0 | divided_by: 4 %}
            {% if program['SubIndication4Phase'] == 'Preclinical' %}
            {% assign percentComplete = 1 | plus: percentOfPhase %}
            {% elsif program['SubIndication4Phase'] == 'Phase 1' %}
            {% assign percentComplete = 25 | plus: percentOfPhase %}
            {% elsif program['SubIndication4Phase'] == 'Phase 2' %}
            {% assign percentComplete = 50 | plus: percentOfPhase %}
            {% elsif program['SubIndication4Phase'] == 'Phase 3' %}
            {% assign percentComplete = 75 | plus: percentOfPhase %}
            {% endif %}
            <div class="home-program__progress" style="width:{{percentComplete}}%"></div>
            <p class="home-program__phase">{{program['SubIndication4Phase']}}</p>
            {% endif%}

            {% if program['SubIndication5'] != '' and program['SubIndication5'] != null %}
            <h3 class="home-program__subindication">{{program['SubIndication5']}}</h3>
            {% assign percentOfPhase = program['SubIndication5PhaseComplete'] | plus: 0 | divided_by: 4 %}
            {% if program['SubIndication5Phase'] == 'Preclinical' %}
            {% assign percentComplete = 1 | plus: percentOfPhase %}
            {% elsif program['SubIndication5Phase'] == 'Phase 1' %}
            {% assign percentComplete = 25 | plus: percentOfPhase %}
            {% elsif program['SubIndication5Phase'] == 'Phase 2' %}
            {% assign percentComplete = 50 | plus: percentOfPhase %}
            {% elsif program['SubIndication5Phase'] == 'Phase 3' %}
            {% assign percentComplete = 75 | plus: percentOfPhase %}
            {% endif %}
            <div class="home-program__progress home-program__progress--{{color}}" style="width:{{percentComplete}}%"></div>
            <p class="home-program__phase">{{program['SubIndication5Phase']}}</p>
            {% endif%}
            <a href="/programs#{{program['Name'] | replace: ' ', '-' | downcase}}">
            <div class="home-program__detail">
                <p class="home-program__detail-text">
                    <h2 class="home-program__title">{{program['Name']}}</h2>
                    {{program['ShortDescriptionHome'] | replace: "<p>", "" | replace: "</p>", "<br/>" | truncatewords: 20}}
                </p>
            </div>
            </a>
            </div>
            {% endfor %}
        </div>




        {% comment %}Display remaning items in grid {% endcomment %}
        <div class="home-program__items-wrapper">
            {% for program in this.items offset:1  %}
            
            {% comment %}Select item color based on condition {% endcomment %}
            
            {% if program['Condition'] == 'hypertrophic cardiomyopathy' %}
            {% assign color = 'red' %}
            {% elsif program['Condition'] == 'diastolic heart failure' %}
            {% assign color = 'teal' %}
            {% elsif program['Condition'] == 'systolic heart failure' %}
            {% assign color = 'blue' %}
            {% endif %}

            <div class="home-program__item home-program__item--{{color}}">
                <h2 class="home-program__title">{{program['Name']}}</h2>

                {% if program['SubIndication1'] != '' and program['SubIndication1'] != null %}
                <h3 class="home-program__subindication">{{program['SubIndication1']}}</h3>
                {% assign percentOfPhase = program['SubIndication1PhaseComplete'] | plus: 0 | divided_by: 4 %}
                {% if program['SubIndication1Phase'] == 'Preclinical' %}
                {% assign percentComplete = 1 | plus: percentOfPhase %}
                {% elsif program['SubIndication1Phase'] == 'Phase 1' %}
                {% assign percentComplete = 25 | plus: percentOfPhase %}
                {% elsif program['SubIndication1Phase'] == 'Phase 2' %}
                {% assign percentComplete = 50 | plus: percentOfPhase %}
                {% elsif program['SubIndication1Phase'] == 'Phase 3' %}
                {% assign percentComplete = 75 | plus: percentOfPhase %}
                {% endif %}
                <div class="home-program__progress home-program__progress--{{color}}" style="width:{{percentComplete}}%"></div>
                <p class="home-program__phase">{{program['SubIndication1Phase']}}</p>
                {% endif%}

                {% if program['SubIndication2'] != '' and program['SubIndication2'] != null %}
                <h3 class="home-program__subindication">{{program['SubIndication2']}}</h3>
                {% assign percentOfPhase = program['SubIndication2PhaseComplete'] | plus: 0 | divided_by: 4 %}
                {% if program['SubIndication2Phase'] == 'Preclinical' %}
                {% assign percentComplete = 1 | plus: percentOfPhase %}
                {% elsif program['SubIndication2Phase'] == 'Phase 1' %}
                {% assign percentComplete = 25 | plus: percentOfPhase %}
                {% elsif program['SubIndication2Phase'] == 'Phase 2' %}
                {% assign percentComplete = 50 | plus: percentOfPhase %}
                {% elsif program['SubIndication2Phase'] == 'Phase 3' %}
                {% assign percentComplete = 75 | plus: percentOfPhase %}
                {% endif %}
                <div class="home-program__progress" style="width:{{percentComplete}}%"></div>
                <p class="home-program__phase">{{program['SubIndication2Phase']}}</p>
                {% endif%}

                {% if program['SubIndication3'] != '' and program['SubIndication3'] != null %}
                <h3 class="home-program__subindication">{{program['SubIndication3']}}</h3>
                {% assign percentOfPhase = program['SubIndication3PhaseComplete'] | plus: 0 | divided_by: 4 %}
                {% if program['SubIndication3Phase'] == 'Preclinical' %}
                {% assign percentComplete = 1 | plus: percentOfPhase %}
                {% elsif program['SubIndication3Phase'] == 'Phase 1' %}
                {% assign percentComplete = 25 | plus: percentOfPhase %}
                {% elsif program['SubIndication3Phase'] == 'Phase 2' %}
                {% assign percentComplete = 50 | plus: percentOfPhase %}
                {% elsif program['SubIndication3Phase'] == 'Phase 3' %}
                {% assign percentComplete = 75 | plus: percentOfPhase %}
                {% endif %}
                <div class="home-program__progress" style="width:{{percentComplete}}%"></div>
                <p class="home-program__phase">{{program['SubIndication3Phase']}}</p>
                {% endif%}

                {% if program['SubIndication4'] != '' and program['SubIndication4'] != null %}
                <h3 class="home-program__subindication">{{program['SubIndication4']}}</h3>
                {% assign percentOfPhase = program['SubIndication4PhaseComplete'] | plus: 0 | divided_by: 4 %}
                {% if program['SubIndication4Phase'] == 'Preclinical' %}
                {% assign percentComplete = 1 | plus: percentOfPhase %}
                {% elsif program['SubIndication4Phase'] == 'Phase 1' %}
                {% assign percentComplete = 25 | plus: percentOfPhase %}
                {% elsif program['SubIndication4Phase'] == 'Phase 2' %}
                {% assign percentComplete = 50 | plus: percentOfPhase %}
                {% elsif program['SubIndication4Phase'] == 'Phase 3' %}
                {% assign percentComplete = 75 | plus: percentOfPhase %}
                {% endif %}
                <div class="home-program__progress" style="width:{{percentComplete}}%"></div>
                <p class="home-program__phase">{{program['SubIndication4Phase']}}</p>
                {% endif%}

                {% if program['SubIndication5'] != '' and program['SubIndication5'] != null %}
                <h3 class="home-program__subindication">{{program['SubIndication5']}}</h3>
                {% assign percentOfPhase = program['SubIndication5PhaseComplete'] | plus: 0 | divided_by: 4 %}
                {% if program['SubIndication5Phase'] == 'Preclinical' %}
                {% assign percentComplete = 1 | plus: percentOfPhase %}
                {% elsif program['SubIndication5Phase'] == 'Phase 1' %}
                {% assign percentComplete = 25 | plus: percentOfPhase %}
                {% elsif program['SubIndication5Phase'] == 'Phase 2' %}
                {% assign percentComplete = 50 | plus: percentOfPhase %}
                {% elsif program['SubIndication5Phase'] == 'Phase 3' %}
                {% assign percentComplete = 75 | plus: percentOfPhase %}
                {% endif %}
                <div class="home-program__progress" style="width:{{percentComplete}}%"></div>
                <p class="home-program__phase">{{program['SubIndication5Phase']}}</p>
                {% endif%}
                <a href="/programs#{{program['Name'] | replace: ' ', '-' | downcase}}">
                <div class="home-program__detail">
                    <p class="home-program__detail-text">
                        <h2 class="home-program__title">{{program['Name']}}</h2>
                        {{program['ShortDescriptionHome'] | replace: "<p>", "" | replace: "</p>", "<br/>" | truncatewords: 100}}
                    </p>
                </div>
                </a>
            </div>
            {% endfor %}
        </div>
    </div>
 </section>

Do you still have the weighting values saved in the items?
I’ve found weighting overrides other sorting methods if the values are present, even if explicitly sorting by another field.

I do have weighting… maybe I need to make a custom sorting value for each location. I’ll try

That worked. Thanks @Adam.Wilson

Seems like a bug

Yes, I would agree. It basically makes the weighting field unusable if you need to sort by any other methods.

As a workaround, there is that Liquid sort filter trick for sorting collections… I can’t recall it from memory but I’ll try and find the code snippet and post it here.

1 Like