我使用JQuery Tablesorter版本2.17.8對錶格進行排序
我創建了一個自定義分析器來排序日期,然後是時間,由一個可選的字符串。JQuery Tablesorter:emptyTo:'bottom'對於自定義分析器不起作用
解析器看起來像這樣:
$.tablesorter.addParser({
id: "datetime",
is: function (s) {
return /\d{2}\-\d{2}\-\d{2}\s\d{2}:\d{2}(door \w+)?/.test(s);
}, format: function (s) {
arr = s.split(/[\s\-:]/);
if(arr[0] == "") // table column is empty
timestamp = null;
else {
// Month is zero-indexed so subtract one from the month inside the constructor
date = new Date(Date.UTC('20' + arr[2], arr[1] - 1, arr[0], arr[3], arr[4])); // Y M D H M
timestamp = date.getTime();
}
console.log(timestamp);
return timestamp;
}, type: "numeric"
});
表列的實施例的數據進行排序:
- 30-04-14 9點55
- 30-04-14 14 :11門I1
- 空細胞
解析器瓦特按預期的方式,但我希望空單元格被排序到底部,似乎沒有工作。
我把這個在我的PHP文件:
<script type="text/javascript">
{literal}
$(document).ready(function()
{
$("#betalingen").tablesorter({
headers: {
5 : { sorter: false } }, // disable sorting for column #5
widgets: ["saveSort", "zebra"], // apply alternating row coloring
sortList: [[2,0]], // initial sorting order for Date column = ascending (0)
emptyTo: 'bottom' // empty cells are always at the bottom
}
);
});
{/literal}
</script>
請注意,我在這裏已經想盡選項:http://mottie.github.io/tablesorter/docs/example-option-sort-empty.html
當我刪除我的自定義分析器(讓的tablesorter找出一個解析器),它按照預期將空單元排序到底部,但顯然該列沒有正確排序。
任何人都知道這裏發生了什麼?
數據真的是空的嗎?或者它是空的? – karlingen 2014-09-23 15:01:30