JQuery 的DataTables的文档很差。很抱歉可能是微不足道的问题。
我想通过某些列上的某些字符串过滤我的表。这是我的代码:
var str = "days";
my_table.fnFilter(str, 9);
我希望在 9 列(从 0 开始计数)中只有包含“days”字符串的行。但上面的代码并没有给我带来结果
我曾尝试将此代码与 RexEx 一起使用:
var regEx = "days";
my_table.fnFilter(regEx, 9, true);
这段代码:
var regEx = "^days$";
my_table.fnFilter(regEx, 9, true);
这个代码:
var regEx = ".*days.*";
my_table.fnFilter(regEx, 9, true);
一切都没有运气。我确定我的表在第 9 列有“101 天”字符串。我究竟做错了什么?
更新:我的专栏有自定义类型:
jQuery.fn.dataTableExt.oSort['days-asc'] = function (a, b) {
var x = parseInt((trim(a) == "") ? 0 : trim(a.replace(/days/, "")));
var y = parseInt((trim(b) == "") ? 0 : trim(b.replace(/days/, "")));
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['days-desc'] = function (a, b) {
var x = parseInt((trim(a) == "") ? 0 : trim(a.replace(/days/, "")));
var y = parseInt((trim(b) == "") ? 0 : trim(b.replace(/days/, "")));
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
更新 2: 我的表初始化选项:
$.my_table = $("#myTable").dataTable({
"iDisplayLength": 10,
"bStateSave": false,
"bFilter": true,
"bSort": true,
"bAutoWidth": false,
"oLanguage": {
"sLengthMenu": sStdMenu + " per page"
},
"sPaginationType": "full_numbers",
"sDom": 'rti<"bottom2"p><"bottom1"l',
"aaSorting": [
[0,'asc']
],
"aoColumns": [
{ "sType": "html-trimmed" },
{ "sType": "date-direct" },
{ "sType": "date-direct" },
{ "sType": "html" },
{ "sType": "percent" },
{ "sType": "money" },
{ "sType": "money" },
{ "sType": "money" },
{ "sType": "days" },
{ "sType": "days" },
{ "sType": "days" },
{ "sType": "days" },
{ "sType": "days" },
{ "sType": "days" },
{ "sType": "html" },
{ "sType": "html" },
null,
null,
null
]
});