使用 Jquery 数据表对数据排序属性中的值进行自定义排序 [英] Custom sorting on values in a data-sort attribute with Jquery Datatables

查看:19
本文介绍了使用 Jquery 数据表对数据排序属性中的值进行自定义排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须对 Jquery 数据表进行一些自定义排序.我不想为每个自定义排序编写自定义排序函数.

I have to do some custom sorts with Jquery Datatables. I do not want to write custom sort functions for every custom sort.

如果定义了值,我想定义一个值进行排序并让数据表忽略原始列值.

I want to define a value to sort on and have Datatables ignore the original column values, if value is defined.

例如:

E 1.111,23

我希望 Jquery 数据表在 111123 上对这一列进行数字排序.

I want Jquery Datatables to sort this column numerically on 111123.

<td data-sort="19801220">20-12-1980</td>

我希望 Jquery 数据表在 19801220 上对这一列进行数字排序.

I want Jquery Datatables to sort this column numerically on 19801220.

一个字符串

我希望 Jquery Datatables 按其原始值对该列进行排序a string.

I want Jquery Datatables to sort this column by its original value a string.

http://www.datatables.net/plug-ins/sorting 有隐藏标题数字排序"与我想要的很接近,但需要我为每个数据表指定此自定义排序适用的列.我有太多不同大小的数据表,无法在合理的时间内完成此操作.我只是想让 Datatables 总是对这个隐藏的值/data-* 属性进行排序(如果它存在的话).无需对特定列进行自定义排序定义.

http://www.datatables.net/plug-ins/sorting has "Hidden title numeric sorting" which is close to what I want, but requires me to specify for every datatable on which column this custom sorting applies. I have too many datatables of differing sizes to do this in a reasonable time. I just want to make Datatables always sort this hidden value / data-* attribute if it is present. No need for custom sort definitions on specific columns.

相关:jQueryDataTables:如何按自定义参数值而不是单元格内容排序?但不幸的是,没有关于如何简单地按自定义参数排序的答案,而是指向自定义排序脚本的指针.

Related: jQuery DataTables: how to sort by custom parameter value rather than the content of the cell? but unfortunately no answer as to how to sort simply by custom parameter, instead pointers to custom sorting scripts.

推荐答案

可以使用 data-order attr,例如

You can use data-order attr, for example

<table class="table table-bordered table-hover">
<thead>
    <tr>
        <th>Date</th>
        <th>Count</th>
    </tr>
</thead>
<tbody>
<?php
   $count = 0;
   foreach($users as $user) {?>
      <tr>
         <td data-order="<?php echo $count ?>">
            <?php echo $user['createdDate']; ?>
         </td>
         <td>
            <?php echo $user['count']; ?>
         </td>
         </tr>
   <?php
      $count++;
   }?>
   <tr>
      <td data-order="999999999999999999999999999"> <!--always last-->
          Total
      </td>
      <td>
         <?php echo count($users); ?>
      </td>
  </tr>

更多信息HTML5 data-* 属性

这篇关于使用 Jquery 数据表对数据排序属性中的值进行自定义排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆