Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在智能表格中按日期对项目进行排序_Javascript_Html_Angularjs_Smart Table - Fatal编程技术网

Javascript 如何在智能表格中按日期对项目进行排序

Javascript 如何在智能表格中按日期对项目进行排序,javascript,html,angularjs,smart-table,Javascript,Html,Angularjs,Smart Table,如何在智能表中按日期对数据进行排序?用st-sort就没那么好了 <table st-table="displayedCollection" st-safe-src="playerCollection" class="table table-hover"> <thead> <tr> <th st-sort="id" class="hover">Id</th> &

如何在智能表中按日期对数据进行排序?用st-sort就没那么好了

<table st-table="displayedCollection" st-safe-src="playerCollection" class="table table-hover">
      <thead>
        <tr>
            <th st-sort="id" class="hover">Id</th>
            <th st-sort="firstname" class="hover">Jméno</th>
            <th st-sort="lastname" class="hover">Příjmení</th>
            <th st-sort="registrationDate" class="hover">Datum registrace</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="player in displayedCollection">
            <td class="hover">{{player.id}}</td>
            <td class="hover">{{player.firstname}}</td>
            <td class="hover">{{player.lastname}}</td>
            <td class="hover">{{player.registrationDate}}</td>
        </tr>
      </tbody>
  </table>

身份证件
杰梅诺
Příjmení
基准注册
{{player.id}
{{player.firstname}
{{player.lastname}
{{player.registrationDate}

感谢您的回答。

向您的
ng重复添加订单,如下所示:

<tr ng-repeat="player in displayedCollection | orderBy:'registrationDate'">
   <td class="hover">{{player.id}}</td>
   <td class="hover">{{player.firstname}}</td>
   <td class="hover">{{player.lastname}}</td>
   <td class="hover">{{player.registrationDate}}</td>
</tr>
<table st-table="displayedCollection" st-safe-src="playerCollection" class="table table-hover">
  <thead>
    <tr>
        <th st-sort="id" class="hover"><a href="" ng-click="predicate = 'id'; reverse=false">Id</a></th>
        <th st-sort="firstname" class="hover"><a href="" ng-click="predicate = 'firstname'; reverse=false">Jméno</a></th>
        <th st-sort="lastname" class="hover"><a href="" ng-click="predicate = 'lastname'; reverse=false">Příjmení</a></th>
        <th st-sort="registrationDate" class="hover"><a href="" ng-click="predicate = 'registrationDate'; reverse=false">Datum registrace</a></th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="player in displayedCollection | orderBy:predicate:reverse">
        <td class="hover">{{player.id}}</td>
        <td class="hover">{{player.firstname}}</td>
        <td class="hover">{{player.lastname}}</td>
        <td class="hover">{{player.registrationDate}}</td>
    </tr>
  </tbody>
</table>
我为此制作了一个plunker。您将看到,如果单击列标题,它将按该列对表进行排序。我希望有帮助

它应该正常工作(参见文档网站)。但是,如果您的注册日期是一个日期字符串,则应该使用getter返回该字符串的日期对象版本,否则您将使用字母数字顺序

在控制器中

$scope.getters = {
   registrationDate:function(row) {
      return new Date(row.registrationDate);
   }
}
因此,您可以将头绑定到此getter

<th st-sort="getters.registrationDate">Datum registrace</th>
基准注册

我将添加另一个与@laurent answer相关的可能解决方案。他的解决方案在我的情况下不起作用,所以我对getter做了一些修改:

$scope.getters = {
   registrationDate:function(row) {
      return (new Date(row.registrationDate)).getTime();
   }
}

getTime()
返回自1970/01/01以来的毫秒数,因此该列将按数字而不是日期排序(在我的情况下它不起作用,我也不知道为什么),结果是相同的。

谢谢,但它仅在页面加载时按日期排序。但我想点击排序。好的,让我看看。@VáclavPavlíček签出编辑后的响应并点击它是正确的方式,应该是公认的答案。我知道这是一个旧线程,但我也面临排序问题。我有以毫秒为单位的日期,当我使用(新日期(1496987379155))将其转换为人类可读的格式时,排序不起作用,我的行只有一半正确排序,另一半未排序。