0

i'm developing an app with Angular 1.4.9 and i'm experiencing some problems with ordering table columns by date.

Here is my code:

HTML

[...]
<table class="table table-hover">
    <thead>
        <tr>
            <th class="header-table-names">
                <a href="" data-ng-click="ctrl.order('creationDate')">
                    Creation date
                    <span data-ng-show="order.predicate === 'creationDate' && !order.reverse" class="fa fa-caret-down"></span>
                    <span data-ng-show="order.predicate === 'creationDate' && order.reverse" class="fa fa-caret-up"></span>
                </a>
            </th>
            <th class="header-table-names">
                <a href="" data-ng-click="ctrl.order('sendDate')">
                    Send date
                    <span data-ng-show="order.predicate === 'sendDate' && !order.reverse" class="fa fa-caret-down"></span>
                    <span data-ng-show="order.predicate === 'sendDate' && order.reverse" class="fa fa-caret-up"></span>
                </a>
            </th>
            <th class="header-table-names">
                <a href="" data-ng-click="ctrl.order('type')">
                    Type
                    <span data-ng-show="order.predicate === 'type' && !order.reverse" class="fa fa-caret-down"></span>
                    <span data-ng-show="order.predicate === 'type' && order.reverse" class="fa fa-caret-up"></span>
                </a>
            </th>
            <th class="header-table-names">
                <a href="" data-ng-click="ctrl.order('subject')">
                    Type
                    <span data-ng-show="order.predicate === 'subject' && !order.reverse" class="fa fa-caret-down"></span>
                    <span data-ng-show="order.predicate === 'subject' && order.reverse" class="fa fa-caret-up"></span>
                </a>
            </th>
        </tr>
    </thead>

    <tbody>
        <tr class="document-list-element" data-ng-repeat="doc in documents">
          <td>{{doc.date | date:'dd/MM/yyyy'}}</td>
          <td>{{doc.dateAdded | date:'dd/MM/yyyy - HH:mm'}}</td>
          <td>{{doc.type}}</td>
          <td>{{doc.subject}}</td>
        </tr>
    </tbody>
</table>
[...]

JAVASCRIPT

[...]
function order(predicate) {
  order.reverse = (order.predicate === predicate) ? !order.reverse : false;
  order.predicate = predicate;
  loadDocuments(true);
}

[...]

function loadDocuments(docs, order) {
  var temp = docs;

  if (order === null) {
    return temp;
  }

  temp = $filter('orderBy')(temp, order.predicate, order.reverse);

  return temp;
}
[...]

Here is an example of the properties Date of the doc object:

Date 2016-01-04T19:32:08.452Z
Date 2016-03-17T18:11:21.702Z

The order by type and subject work with no problems. The order by date doesn't. It seems to correctly order the documents, but it actually doesn't.

smartmouse
  • 11,808
  • 26
  • 77
  • 154

0 Answers0