因此,我的所有列都排序没有问题,但“媒体”列除外,该列显示文件大小限制(GB,TB等)的配额。我怀疑Rails NumberHelpernumber_to_human_size
与tablesorter配合不好。任何人都有一个想法,如何利用NumberHelper进行排序?
_table.html.haml
%table#myTable.tablesorter
%thead
%tr
%th Name
%th.right Per Month
%th.right Members
%th.right Additional
%th.right Media
%th.right Subscriptions
- if @plans.any?
%tbody
- @plans.each do |plan|
%tr
%td
= link_to admin_plan_path(plan) do
= plan.name
%td.right
= "$ #{plan.base_price_in_cents / 100}"
%td.right
= plan.included_users
%td.right
= "$ #{plan.price_in_cents / 100}"
%td.right
= number_to_human_size(plan.media_data_quota) || '∞'.html_safe
%td.right
= link_to organizations_admin_plan_path(plan) do
= plan.subscriptions.count
application.js
$(document).ready(function()
{
$("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} );
}
);
为了使文件大小正确排序,您需要一个解析器将“ GB”和“ TB”等转换为可排序的数字。
我的tablesorter分支上有一个度量标准解析器-演示,它同时转换度量标准和二进制值以进行排序。
要使用它,请加载解析器文件,然后添加sorter-metric
anddata-metric-name
属性:
<th class="sorter-metric" data-metric-name="b|byte">Media</th>
我尚未对其进行测试,但是如果您使用的是原始表排序器,则此解析器仍然可以正常工作。如果是这种情况,则排序器类名称将不起作用,因此您需要设置以下headers
选项:
headers: {
0 : { sorter: 'metric' }
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句