0

我有一个表,其中有一个名为 Goal 的列,该表充满了这样的红宝石:

<table  data-sorted="myTable">
  <thead>
    <tr>
      <th><a rel="tooltip" title="Name">Name</a></th>
      <th>subname</th>
      <th>Days</th>
      <th>%</th>
      <th>Goal</th>
      <th>achieved</th>
    </tr>
  </thead>
<tbody>
 <% @results.each do |id, rows| %>
 <% rows.each do |row| %>
    <tr>
      <td>
        <b><%= row[:name] %></b></td>
      <td><%= row[:subname] %></td>
      <td><%= row[:days] %></td>
      <td class="<%= status_indicator(row[:percentage].to_f) %>"><%= number_to_percentage(row[:percentage], :precision => 2)%></td>
      <td class="{sorter: 'thousands'}"="<%= row[:goal].to_i %>"><%=number_with_delimiter(row[:goal].to_i) %></td>
      <td class="achieved"><%= row[:achieved].to_i %></td>
    </tr>
  <% end %>
<% end %>
  </tbody>
</table>

根据我的在线研究,我在 jquery 上有这个。

$.tablesorter.addParser({ 
    // set a unique id 
    id: 'thousands',
    is: function(s) { 
        // return false so this parser is not auto detected 
        return /^[0-9]?[0-9,\.]*$/.test(s);
    }, 
    format: function(s) {
        // format your data for normalization 
        return jQuery.tablesorter.formatFloat( s.replace(/,/g,'') );
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
}); 

$(function() {
    $("[data-sorted=myTable]").tablesorter({
        headers: {
            6: {//zero-based column index
                sorter:'thousands'
            }
        }
    });
});

排序在表的所有列中都有效,但在我有一千个分隔符的列上,我得到了这个结果

  1. 这就是表格在加载时开始的方式

这就是表格在加载时开始的方式

  1. 这是排序时表格的呈现方式

这是排序时表格的呈现方式

4

1 回答 1

1

看起来 headers 选项正在将“千”排序器分配给第 7 列(从零开始的索引)

headers: {
    6: {//zero-based column index
        sorter:'thousands'
    }
}

元数据将其分配给第 5 列

<td class="{sorter: 'thousands'}"...

因此,要么您需要添加元数据插件以使类名起作用,要么更改您的标题选项以定位正确的列:

headers: {
    4: {//zero-based column index
        sorter:'thousands'
    }
}
于 2013-09-17T20:10:15.823 回答