2015-11-02 52 views
2

我正在使用Mottie的Tablesorter(https://github.com/Mottie/tablesorter),我試圖在格式化的單元格上使用Math小部件;Tablesorter數學小部件使用數據*

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

但是我似乎無法找出如何通過對arrymath-complete選項傳遞data-*;

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

+0

http://stackoverflow.com/questions/4187032/get-list-of-data-attributes-using-javascript-jquery –

+0

我要求將它集成到TableSorter中,因爲我希望使用'math_event'選項。這個解決方案只是一個通用的jQuery解決方案。 – psycotik

回答

1

數學小部件設置爲得到一個數據屬性由textAttribute選項設置信息。所以,如果你想使用data-number,設置屬性爲"data-number"demo):

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

如果您需要在某些列中使用「textAttribute」,並在其他列中使用單元格值,該怎麼辦? – psycotik

+0

數學小部件只會抓取數據屬性值(如果存在),所以如果您想使用單元格值,請不要添加「數據編號」屬性。或者你是否說非數學單元格會使這種方法搞砸? – Mottie

+0

我的理解是,我有一個情況,我想在兩個不同的列上使用數學小部件,它似乎正常工作,如果這兩個列不同,我將textAttribute設置爲'data-number',其中'data-number'不可用,它使用默認值。 – psycotik

相關問題