Sorting Angularjs ng-repeat by date
<p>I am relatively new to AngularJS. Could use some help</p>

<p>I have a table with the following info</p>

<pre><code>&lt;table&gt;
 &lt;tr&gt;
  &lt;th&gt;&lt;span ng-click="sortType = 'first_name'; sortReverse = !sortReverse"&gt;Referral Name&lt;/span&gt;&lt;/th&gt;
  &lt;th&gt;&lt;span ng-click="sortType = 'date'; sortReverse = !sortReverse"&gt;Referral Name&lt;/span&gt;&lt;/th&gt;
 &lt;/tr&gt;
 &lt;tr ng-repeat="x in referral | orderBy:sortType:sortReverse"&gt;
  &lt;td&gt;name&lt;/td&gt;
  &lt;td&gt;date&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tabe&gt;
</code></pre>

<p>And the js code is as follows (after the controller connections)</p>

<pre><code>$scope.sortType = '';
$scope.sortReverse = false;
</code></pre>

<p>This works perfectly for ascending and descending when sorting the name.</p>

<p>Unfortunately it works similarly in the case of date too (it is sorting alphabetically, rather than by date).</p>

<p>The date format I am getting from the backend(python) is in this format:</p>

<pre><code>i["date"] = i["date"].strftime("%B %d, %Y")
September 13, 2016 &lt;-- this format
</code></pre>

<p>I understand the mistake I made, but I am not able to find the solution for it.</p>

<p>How can I sort by date? </p>

<p>Thanks in advance guys.</p>

<p>Ideally you'd have a sortable object for date.  One candidate is an isoformatted date:</p>

<pre><code>i["date"] = i["date"].isoformat()
</code></pre>

<p>Now sorting should work just fine but it'll display wonky.  So you'll need to use a date filter to format it on the UI:</p>

<pre><code>&lt;table&gt;
 &lt;tr&gt;
  &lt;th&gt;&lt;span ng-click="sortType = 'first_name'; sortReverse = !sortReverse"&gt;Referral Name&lt;/span&gt;&lt;/th&gt;
  &lt;th&gt;&lt;span ng-click="sortType = 'date'; sortReverse = !sortReverse"&gt;Referral Name&lt;/span&gt;&lt;/th&gt;
 &lt;/tr&gt;
 &lt;tr ng-repeat="x in referral | orderBy:sortType:sortReverse"&gt;
  &lt;td&gt;name&lt;/td&gt;
  &lt;td&gt;{{x.date | date : 'MMMM d, yyyy'}}&lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;
</code></pre>

python html angularjs sorting