我在整理包含浮點數和整數列問題:JQUERY的tablesorter不排序數字列正確
例
目前列進行排序,像這樣:
4697.2
403.95
399.38
317.94
316.44
3138.7
308.28
262.75
1839.5
179.94
159.97
145.99
103.95
94.95
90.24
819.9
我想按價值對列進行排序,因爲它似乎是按字符長度對數字進行排序 - 可能嗎?
這裏是我的javascript:
<script>
$(function(){
$('table').tablesorter({
widgets : ['zebra', 'columns', 'stickyHeaders'],
usNumberFormat : false,
numberSorter: function (a, b, direction) {
if (a >= 0 && b >= 0) { return direction ? a - b : b - a; }
if (a >= 0) { return -1; }
if (b >= 0) { return 1; }
return direction ? b - a : a - b;
}
});
});
</script>
可能有人請讓我知道我需要做糾正呢? 謝謝
只是一個猜測,但你設置usNumberFormat假,然後分揀機應該會像430,95數值...要麼改變你的價值觀,或者使用真 – fuchs777 2014-09-30 10:53:35
@ fuchs777 - 偉大的建議!這是現在的工作,謝謝 – aphextwix 2014-09-30 10:59:18
爲什麼你需要'numberSorter'中額外的代碼?沒有它,它應該正常工作。 – Mottie 2014-10-02 17:34:43