如何使用st-table按日期时间对数据进行排序

时间:2017-11-20 06:42:35

标签: javascript angularjs angularjs-directive angularjs-ng-repeat

我有以下代码我的数据没有根据日期时间排序请帮助我这个我正在使用<div st-pagination="" st-items-by-page="10" st-displayed-pages="7"></div>我认为它的显示问题,检查下面的代码我有超过30条记录,这就是为什么排序问题

<table st-table='displayedAssets' st-safe-src="assetController.assetsData" class="table table-bordered table-striped table-hover table-condensed mb-none dataTable no-footer">
    <thead>
        <tr>
            <td colspan="9">
                <ul class="list-inline list-unstyled">
                    Search
                    <li><input st-search="city" placeholder="City" class="input-sm form-control" type="search" /></li>
                    <li> <input st-search="region" placeholder="Region" class="input-sm form-control" type="search" /></li>
                    <li><input st-search="medium" placeholder="Medium" class="input-sm form-control" type="search" /></li>
                </ul>
            </td>
        </tr>
        <tr>
            <th>City</th>
            <th>create date</th>
            <th>Location</th>

        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in displayedAssets | orderBy:'created_date':true ">
            <td>{{ row.city }}</td>
            <th>{{ row.created_date }}</th>

            <td>{{ row.location }}</td>

            <td>
                <button type="button" title="Delete" ng-click="assetController.showConfirm($event, row)" class="btn btn-sm btn-danger">
                    <i class="glyphicon glyphicon-remove-circle">
                    </i>
                </button>
            </td>
        </tr>
    </tbody> 
    <tfoot>
        <tr>
            <td colspan="9" class="text-right">
                <div st-pagination="" st-items-by-page="10" st-displayed-pages="7"></div>
            </td>
        </tr>
    </tfoot>
</table> 

angularjs js

this.$http.get('/api/assets')
      .then(response => {
        this.assetsData = response.data;     
        this.socket.syncUpdates('asset', this.assetsData);
});

1 个答案:

答案 0 :(得分:0)

日期排序

&#13;
&#13;
let dateTimeArr = ["11/14/13 12:07","12/13/11 01:07","09/09/12 09:04","08/30/14 19:05","04/24/04 16:03","08/15/16 10:02","12/13/11 02:07"]

let sortedArr = dateTimeArr.sort((a,b)=>{
	return new Date(a).getTime() - new Date(b).getTime();
})

console.log(sortedArr);
&#13;
&#13;
&#13;