ng-table过滤器毫秒日期数据

时间:2016-02-10 14:46:16

标签: javascript angularjs ngtable

我的日期数据来自JSON,以毫秒为单位。我已使用{{date | date:Filter}}在视图中对其进行了过滤,但过滤器不起作用。当我在输入过滤器字段中写入时,它实际上在毫秒数据上工作。 如何使过滤器处理已过滤的视图数据?

$scope.tableParams = new ngTableParams({
    page: 1,            // show first page
    count: 10,
    sorting: {
        creationDate: 'desc'
    }
}, {
    counts: [],
    total: $scope.pagainationRslt.length, 
    getData: function ($defer, params) {
            // use build-in angular filter
            var filteredData = params.filter() ?
            $filter('filter')($scope.pagainationRslt, params.filter()) :
            $scope.pagainationRslt;
            var orderedData = params.sorting() ?
            $filter('orderBy')(filteredData, params.orderBy()) :
                $scope.pagainationRslt;

            params.count($scope.currentCount)
            params.total(orderedData.length)
            $defer.resolve(orderedData);

    } 
});  

和html:

<table ng-table="tableParams" show-filter="true"class="ui collapsing celled striped table">
    <tr ng-repeat="item in $data">
    <td sortable="'date'" filter="{ 'date' : 'text' }">{{item.date | date:dateEUFormat}}</td>
    </tr>
</table>

1 个答案:

答案 0 :(得分:0)

对于日期格式,请添加正确的格式字符串,如下所示:

<table ng-table="tableParams" show-filter="true"class="ui collapsing celled striped table">
    <tr ng-repeat="item in $data">
    <td sortable="'date'" filter="{ 'date' : 'text' }">{{item.date | date: 'dd-MMM-yyyy HH:mm'}}</td>
    </tr>
</table>

以下是一个完整的示例:https://jsbin.com/xetonidina/edit?html,js,output

我仍然不确定你的日期是否格式错误,即。 1455235722而不是1455235722667.如果那是问题所在:

<table ng-table="tableParams" show-filter="true"class="ui collapsing celled striped table">
    <tr ng-repeat="item in $data">
    <td sortable="'date'" filter="{ 'date' : 'text' }">{{(item.date * 1000) | date: 'dd-MMM-yyyy HH:mm'}}</td>
    </tr>
</table>