Answers.Body: <p>You can't do that with core Craft functionality or Twig filters, but as Mats already suggested in the comments, you can do it with a plugin like <a href="http://michaelrog.com/craft/lagniappe/supersort" rel="nofollow">"Super Sort"</a>.</p>
  
  <p>The template code to sort the array returned from the table field with that plugin would be:</p>
  
  <pre><code>{% for row in entry.tablefield|supersort('sortAs', '{{ object.firstName }}') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-07T20:36:07.710Z
Answers.LastActivityDate: 2015-05-07T21:03:37.157Z
Answers.LastEditDate: 2015-05-07T21:03:37.157Z
Answers.UserDisplayName: carlcs
Body: <p>Guess this is a stupid question, but I'm trying to sort a table based on which column the user wants to sort.</p>
  
  <p>Tried:</p>
  
  <p><code>{% for row in entry.tablefield|sort %}</code> (No effect)</p>
  
  <p><code>{% for row in entry.tablefield.order('firstName') %}</code> (Error message)</p>
  
  <p>Anyone who know if this is possible or know how to do this?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-07T20:30:26.170Z
Comments.Text: Have you looked at the [SuperSort plugin](http://michaelrog.com/craft/lagniappe/supersort)?
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Tags: <templating><sorting>
Title: Want to sort a table field from Twig
ThreadText: # Want to sort a table field from Twig
  
  (Asked by: username_0 on 2015-05-07)
  
  Guess this is a stupid question, but I'm trying to sort a table based on which column the user wants to sort.
  
  Tried:
  
  `{% for row in entry.tablefield|sort %}` (No effect)
  
  `{% for row in entry.tablefield.order('firstName') %}` (Error message)
  
  Anyone who know if this is possible or know how to do this?
  
  **Tags:** templating, sorting
  
  > **Comments:**
  > **username_1**: Have you looked at the [SuperSort plugin](http://michaelrog.com/craft/lagniappe/supersort)?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-05-07. Score: 6 | Accepted answer
  
  You can't do that with core Craft functionality or Twig filters, but as username_1 already suggested in the comments, you can do it with a plugin like ["Super Sort"](http://michaelrog.com/craft/lagniappe/supersort).
  
  The template code to sort the array returned from the table field with that plugin would be:
  
  ```
  {% for row in entry.tablefield|supersort('sortAs', '{{ object.firstName }}') %}
  
  ```
  
  
  ---
  
  