ng 表过滤毫秒日期数据

ng-table filter millisecond date data

本文关键字:日期 数据 过滤 ng      更新时间:2023-09-26

我的日期数据来自以毫秒为单位的 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>

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

<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>