Angular table orderBy 列

Angular table orderBy column

我尝试 angular table 按日期列排序(降序)。但它不起作用(日期列数据类型为字符串,出于某种原因必须获取字符串数据类型).请帮助我。

示例数据

Trans.Date | Receipt / Ref No | Trx Code | Description | Receipt Amt | Debit     | Credit | Running Balance 

2013-08-15 | 000000000001     | OST      |  OST        | 0.00        |  150.00   | 0.00   | 150.00       
2013-08-15 | 000000000001     | OTH      |  Amounts    | 0.00        |  8,000.00 | 0.00   | 8,150.00     
2013-09-15 | 000000000001     | RNT      |  Rental     | 0.00        |  3,041.00 | 0.00   | 11,191.00    
2013-10-15 | 000000000002     | RNT      |  Rental     | 0.00        |  3,041.00 | 0.00   | 14,232.00   

代码

<table id="tblTrans" class="display table-bordered" cellspacing="0" width="100%" style="font-size: small;">
<thead>
    <tr>
        <th>Date</th>
        <th>Receipt / Ref No</th>
        <th>Trx Code</th>
        <th>Description</th>
        <th>Pay Mode</th>
        <th>Receipt Amt</th>
        <th>Debit</th>
        <th>Credit</th>
        <th>Running Balance</th>
    </tr>
</thead>
<tbody>
    <tr ng-repeat="objtrn in transactions | orderBy:'TRNDATE' | startFrom:currentPageTrn*pageSize | limitTo:pageSize ">
        <td>{{objtrn.TRNDATE}}</td>
        <td>{{objtrn.TRNNO}}</td>                               
        <td>{{objtrn.TRNCODE}}</td>
        <td>{{objtrn.DESCR}}</td> 
        <td>{{objtrn.PAYMODE}}</td>  
        <td style="text-align:right">{{objtrn.TRNAMT | number:2}}</td>  
        <td style="text-align:right">{{objtrn.DEBIT | number:2}}</td>  
        <td style="text-align:right">{{objtrn.CREDIT | number:2}}</td>  
        <td style="text-align:right">{{objtrn.RUNBAL | number:2}}</td>  
    </tr>
</tbody>

使用反向参数(参见documentation

语法为:orderBy : expression : reverse : comparator

对于您的情况,将过滤器更改为:

orderBy:'TRNDATE':true

试试这个:orderBy:'-TRNDATE'。我以相反的方式为 id 这样做。所以希望它能帮助你。