[Python] Best way to sort table based on headers using Flask

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have my table that gets generated based on what's in the database and would like to add the ability to sort the table based on particular columns. I tried looking online but since the table isn't static, I'm not sure how to properly add in the ability to sort.

    <table class="table" style="border: 3px solid black;">
    <thead>
    <tr>
    <th style="border-left: 1px solid #eee;" class="align-middle">Select</th>
    <th class="align-middle">Col1</th>
    <th class="align-middle">Col2</th>
    <th class="align-middle">Col3</th>
    <th class="align-middle">Col4</th>
    </tr>
    </thead>
    <tbody>
    {% for row in data %}
    <tr>
    <td><input type="checkbox" name="inputSelect" value="{{ row[0], row[3] }}"></td>
    <td>{{ row[0] }}</td>
    <td>{{ row[1] }}</td>
    <td>{{ row[2] }}</td>
    <td>{{ row[3] }}</td>
    </tr>
    {% endfor %}
    </tbody>
    </table>

    Continue reading...

Compartilhe esta Página