[英]Datatables Individual Column Filtering (Select Tag) : Use Exact Match
我正在使用数据表1.9.4和列过滤插件。 它的工作原理就像一种魅力,只不过当我使用“ select”标签进行列过滤时,过滤器并未针对完全匹配进行。 它使用通配符搜索,这是我不想要的。 我认为使用select元素代替文本输入可以解决问题,但不能解决问题。
当我搜索“ Semester-I”时 ,它应仅显示“ Semester-I”结果。 但是它也显示“ Semester-II”和“ Semester-III”匹配,因为过滤器没有在寻找完全匹配的内容。
我尝试了jQuery DataTable ColumnFilter插件。 “选择”过滤器样式可以支持完全匹配吗? 以及http://code.google.com/p/jquery-datatables-column-filter/issues/detail?id=11该内容。 但是没有一个解决我的问题。
JS代码
$('#semester').dataTable({
"sPaginationType": "full_numbers"
})
.columnFilter({
aoColumns: [ { type: "text"},
{ type: "text" },
{ type: "select", values: [ 'Year - I', 'Year - II', 'Year - III', 'Semester - I', 'Semester - II', 'Semester - III', 'Semester - IV', 'Semester - V', 'Semester - VI', 'Semester - VII ( Integrated )', 'Semester - VIII ( Integrated )', 'Semester - IX ( Integrated )', 'Semester - X ( Integrated )']},
{ type: "text" },
null
]
});
还有其他选择吗? 提前致谢
UPDATE
我也尝试了以下方法,但这也无济于事:
if (bRegex)
oTable.fnFilter($(this).val(), iColumn, bRegex);
else
oTable.fnFilter(unescape("^"+$(this).val()+"$"), iColumn, true);
瞧! 通过一系列的尝试和错误尝试来弄清楚自己。 对于那些遇到类似问题的人,这里是解决方案:
在插件文件中的select.change(function () {})
,更改以下内容:
if (bRegex)
oTable.fnFilter($(this).val(), iColumn, bRegex);
else
oTable.fnFilter(unescape($(this).val()), iColumn);
至
if (bRegex)
oTable.fnFilter($(this).val(), iColumn, bRegex);
else
oTable.fnFilter(unescape("^"+$(this).val()+"$"), iColumn, true, false);
DataTable演示中的 multy过滤器
var asInitVals = new Array();
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"oLanguage": {
"sSearch": "Search all columns:"
}
} );
$("tfoot input").keyup( function () {
/* Filter on the column (the index) of this element */
oTable.fnFilter( this.value, $("tfoot input").index(this) );
} );
/*
* Support functions to provide a little bit of 'user friendlyness' to the textboxes in
* the footer
*/
$("tfoot input").each( function (i) {
asInitVals[i] = this.value;
} );
$("tfoot input").focus( function () {
if ( this.className == "search_init" )
{
this.className = "";
this.value = "";
}
} );
$("tfoot input").blur( function (i) {
if ( this.value == "" )
{
this.className = "search_init";
this.value = asInitVals[$("tfoot input").index(this)];
}
} );
} );
请注意 ,在上面的代码中,提供了支持功能以确保最终用户知道要过滤哪些数据。 fnFilter()是此处的主要导入功能。
// after creating the table and getting the table object...
var oTable = $('#some_id').dataTable();
// ...you can use it to get a settings object...
var oSettings = oTable.fnSettings();
// ...then you can do things with the settings object
oSettings.aoPreSearchCols[ iCol ].sSearch = "^\\s*"+'1'+"\\s*$";
oSettings.aoPreSearchCols[ iCol ].bRegex = false;
oSettings.aoPreSearchCols[ iCol ].bSmart= false;
我使用了可接受的答案,但是,如果更改下拉列表,然后将其更改回默认值,则不会得到任何结果。 我的猜测是,它试图在“”上进行精确的文本搜索,但一无所获。 我进行了修改,看来对我有用。
if ($(this).val() == "")
oTable.fnFilter(unescape($(this).val()), iColumn, false, false, false, false);
else {
if (bRegex)
oTable.fnFilter($(this).val(), iColumn, bRegex, false, false, false);
else
oTable.fnFilter(unescape("^" + $(this).val() + "$"), iColumn, true, false, false, false);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.