Twig sort array of objects by field

后端 未结 8 2107
感动是毒
感动是毒 2020-12-17 09:31

I have entity with fields:

User

  • name
  • lastname
  • age

and few more. Im sending to Twig array with objec

相关标签:
8条回答
  • 2020-12-17 09:51

    You must do this in your model using an "Order by" clause. However, if you want to have a table that can be sorted dynamically, you should watch about the jQuery tablesorter plugin (or equivalent if you do not want to use jQuery).

    http://tablesorter.com/docs/

    0 讨论(0)
  • 2020-12-17 09:54

    Sorting in reverse order:

    {% for user in users|sort|reverse %}
        ...
    {% endfor %}
    

    sort and revers are combinable.

    0 讨论(0)
提交回复
热议问题