【问题标题】:Tablesorter math widget use data-*Tablesorter 数学小部件使用数据-*
【发布时间】:2015-11-02 14:41:17
【问题描述】:

我正在使用 Mottie 的 Tablesorter (https://github.com/Mottie/tablesorter),我正在尝试在格式如下的单元格上使用数学小部件;

<td data-number="50">Fifty</td>

但是我似乎不知道如何在math-complete 选项上将data-* 传递给arry

  math_complete : function($cell, wo, result, value, arry) {
    var txt = '<span class="align-decimal">' +
      ( value === wo.math_none ? '' : '$ ' ) +
      result + '</span>';
    if ($cell.attr('data-math') === 'all-sum') {
      // when the "all-sum" is processed, add a count to the end
      return txt + ' (Sum of ' + arry.length + ' cells)';
    }
    return txt;
  }

另外,我使用的是 v2.18.2。

Documentation Link

【问题讨论】:

标签: jquery tablesorter


【解决方案1】:

数学小部件设置为从textAttribute 选项设置的数据属性中获取信息。所以如果你想使用data-number,将该属性设置为"data-number"demo):

$(function () {
    $('table').tablesorter({
        theme: 'blue',
        textAttribute: 'data-number',
        widgets: ['zebra', 'math']
    });
});

【讨论】:

  • 如果需要在某些列中使用textAttribute而在其他列中使用单元格值怎么办?
  • 数学小部件只抓取数据属性值(如果存在),因此如果要使用单元格值,请不要添加data-number 属性。或者你是说非数学细胞会用这种方法搞砸?
  • 我明白,但是,我有一个案例,我想在两个不同的列上使用数学小部件,&lt;td data-number="50"&gt;Fifty&lt;/td&gt;&lt;td&gt;20&lt;/td&gt; 如果我将 textAttribute 设置为 @987654331,它似乎可以正常工作@,其中data-number 不可用,而是使用默认值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-18
  • 1970-01-01
  • 1970-01-01
  • 2015-08-04
  • 2015-09-20
  • 1970-01-01
相关资源
最近更新 更多