title: Best way to sort table based on headers using Flask
body: <p>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.</p>
  
  <pre><code>&lt;table class="table" style="border: 3px solid black;"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style="border-left: 1px solid #eee;" class="align-middle"&gt;Select&lt;/th&gt;
              &lt;th class="align-middle"&gt;Col1&lt;/th&gt;
              &lt;th class="align-middle"&gt;Col2&lt;/th&gt;
              &lt;th class="align-middle"&gt;Col3&lt;/th&gt;
              &lt;th class="align-middle"&gt;Col4&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          {% for row in data %}
          &lt;tr&gt;
              &lt;td&gt;&lt;input type="checkbox" name="inputSelect" value="{{ row[0], row[3] }}"&gt;&lt;/td&gt;
              &lt;td&gt;{{ row[0] }}&lt;/td&gt;
              &lt;td&gt;{{ row[1] }}&lt;/td&gt;
              &lt;td&gt;{{ row[2] }}&lt;/td&gt;
              &lt;td&gt;{{ row[3] }}&lt;/td&gt;
          &lt;/tr&gt;
          {% endfor %}
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>