Jquery tablesorter
我正在使用,我需要一个sort列,其中包含带有连字符标记的数字。这些数据的格式如下,未能按ASC顺序onLoad:17-143,17-162,12-144,17-45,18-12,17-65,18-2。有些值为空。sql中的空白值。以上数据默认为: 12-144,17-45,17-65,17-143,17-162,18-2,18-12。
请协助。下面是我试图使用的片段:
<script src="https://github.com/christianbach/tablesorter/blob/master/jquery.tablesorter.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#main_gvResource").tablesorter.addParser({
// set a unique id
id: 'lblIDSort',
is: function(s) {
return false;
},
format: function(s) {
return s.replace('$','').replace(/-/g,'');
},
type: 'numeric'
});
$(function() {
$("#main_gvResource").tablesorter({
widgets: ['zebra'],
headers: {
1: {//zero-based column index
sorter:'gdMobileID'
}
}
});
});
});
</script>
发布于 2016-05-06 19:34:07
为什么有这么多空白?你害怕吗,你可能一下子就看到太多的代码了吗?)
$(function() {
$.tablesorter.addParser({
_regex: /^\d+(?:-\d+)+$/,
_formatNumber: function(nr){
//return "0".repeat(5-nr.length) + nr;
while(nr.length < 5) nr = "0" + nr;
return nr;
},
// set a unique id
id: 'gdMobileID',
is: function(s) {
//to auto-recognize the column-type
return this._regex.test(s);
//to apply only on columns you defined
return false;
},
format: function(s){
return s.replace(/\d+/g, this._formatNumber);
},
type: 'text',
});
$("#main-gvResource").tablesorter({
widgets: ['zebra'],
//no need, if you let the parser auto-recognize the columns to apply
/*headers: {
1: {//zero-based column index
sorter:'gdMobileID'
}
}*/
});
});发布于 2016-05-07 17:00:34
默认情况下,我的餐盘叉使用自然排序算法。您不需要包含任何额外的代码来使它与数据集(演示)一起工作。
$(function () {
$('table').tablesorter({
theme: 'blue'
});
});https://stackoverflow.com/questions/37079329
复制相似问题