Angular 数据表:对非文本数据进行排序

Angular datatables: sort non-textual data

有没有办法为包含非文本数据的列创建自定义排序?

这是一张快照:

我想按图标符号排序。

P.S。这两个图标都使用 ng-if 和数据集中的布尔值显示。

编辑:我正在使用 Angular 显示数据的方式。

<table datatable="ng" dt-options="dtOptionsLoginHistory" dt-column-defs="dtColumnDefsLoginHistory"
               class="table table-striped row-border hover"
               width="100%">
            <thead>
            <tr>
                <th>Success</th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="entry in entries">
                <td style="width: 10%;">
                    <i ng-if="!entry.failed" class="fa fa-check" style="color: green;"></i>
                    <i ng-if="entry.failed" class="fa fa-times" style="color: red;"></i>
                </td>
            </tr>
            </tbody>
        </table>

添加 orderBy 过滤器:

  <tr ng-repeat="entry in entries orderBy : 'failed'  "> 
    <td style="width: 10%;">
       <i ng-if="!entry.failed" class="fa fa-check" style="color: green;"></i>
       <i ng-if="entry.failed" class="fa fa-times" style="color: red;"></i> 
    </td>
</tr>

有几种不同的方法可以实现您想要的。考虑到您的设置,我认为最简单的方法是创建一个特殊的 orderType,return 一个基于 fa-*<i> 元素呈现的值:

$.fn.dataTable.ext.order['fa-classes'] = function(settings, col)  {
  return this.api().column( col, {order:'index'} ).nodes().map(function(td, i) {
    return $('i', td).hasClass('fa-check') ? '1' : '0';
  })
} 

将给所有 <i class="fa fa-check"> 订单 1,任何其他 0。这也可以是 switch { .. } returning 多个不同的订单值。像这样使用它:

$scope.dtColumnDefsLoginHistory = [
   DTColumnDefBuilder.newColumnDef(0).withOption('orderDataType', 'fa-classes')
];  

小演示 -> http://plnkr.co/edit/8S5f2MR331CiNBYYfDQf?p=preview