I'm trying to sort the rows of a view in the table template but can't figure out how to sort by a particular column. I can only get it to sort by the first column. I'm trying to sort a views global conditional field so I can't use views query alter. Here's the code that sorts by the first column. I've tried various arrow functions without any luck.((a, b) => a.row.column <=> b.row.column).

  {% for row in rows|sort %}
    <tr{{ row.attributes }}>
      {% for key, column in row.columns %}
        {% if column.default_classes %}
  • Thanks @cilefen I think I asked the question badly. How do I access the column numbers as indicated in the header of the template file? * - rows: Table row items. Rows are keyed by row number. * - attributes: HTML classes to apply to each row. * - columns: Row column items. Columns are keyed by column number.
    – davidp
    Mar 27, 2023 at 23:19
  • I think this is essentially a Twig programming question. It’s hard to formulate an answer not really knowing what are the contents of the data. Output of the dump function would help this Question out.
    – cilefen
    Mar 28, 2023 at 2:04


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.