我按照这个例子:http://www.datatables.net/development/filtering
但它不起作用。如果输入“a”作为搜索键盘,则所有行仍显示在表格中,因为它会搜索html标记<a>
。我错过了什么?
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<script>
$.fn.dataTableExt.ofnSearch['string'] = function ( sData )
{
return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
};
$(document).ready
(
function()
{
$('#search').dataTable
(
{
aoColumns:[
{'sType': 'string'}
]
}
);
}
);
</script>
</head>
<body>
<table id="search">
<thead>
<tr>
<th>search</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="www.google.com">b</a></td>
</tr>
<tr>
<td><a href="www.google.com">c</a></td>
</tr>
<tr>
<td><a href="www.google.com">d</a></td>
</tr>
<tr>
<td><a href="www.google.com">e</a></td>
</tr>
<tr>
<td><a href="www.google.com">f</a></td>
</tr>
<tr>
<td><a href="www.google.com">g</a></td>
</tr>
</tbody>
</table>
</body>
</html>
答案 0 :(得分:2)
从源代码中得到了这个
* Note that as of v1.9, it is typically preferable to use <i>mData</i> to prepare data for
* the different uses that DataTables can put the data to. Specifically <i>mData</i> when
* used as a function will give you a 'type' (sorting, filtering etc) that you can use to
* prepare the data as required for the different types. As such, this method is deprecated.
* @type object
* @default {}
* @deprecated
*
* @example
* $.fn.dataTableExt.ofnSearch['title-numeric'] = function ( sData ) {
* return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
* }
*/
"ofnSearch": {},
所以我想出了这个
var filterFunc = function ( sData )
{
return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
};
$(document).ready
(
function()
{
$('#search').dataTable
(
{
aoColumns:[
{
'mData': function(source, type, val){
if (type === 'set') {
source.value = val;
source.value_display = val;
source.value_filter = val=="" ? "" : filterFunc(val);
return;
}
else if (type === 'display') {
return source.value_display;
}
else if (type === 'filter') {
return source.value_filter;
}
// 'sort', 'type' and undefined all just use the integer
return source.value;
}
}
]
}
);
}
);
答案 1 :(得分:0)
可能你应该为你的“一个”报价
还是$selector.find (a).text()
?