两种方案:
方案一:
http://stackoverflow.com/questions/12517407/how-do-i-ignore-html-when-filtering-a-jquery-data-table
mRender: function(data, type, full) {
// If we're filtering, don't look at the HTML; only filter on the text
return type == 'filter' ? $(data).text() : data
}
方案二:
当表数据为动态时,涉及source赋值的问题。如何设计才能使后一列不会将前一列覆盖,还未解决方案。若有大侠知道答案,请给我点提示,谢谢啦。
当table为动态数据且链接仅为一列时,可参考:
http://stackoverflow.com/questions/16783202/how-to-search-only-text-in-jquery-datatables
当table固定且为多列时,方案如下:
表定义为:
<table id="search">
<thead>
<tr>
<th>search</th>
<th>aaa</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="www.google.com">b</a></td>
<td ><a href="www.google.com">查看</a></td>
</tr>
<tr>
<td><a href="www.google.com">c</a></td>
<td><a href="www.google.com">查看</a></td>
</tr>
<tr>
<td><a href="www.google.com">d</a></td>
<td><a href="www.google.com">查看</a></td>
</tr>
</tbody>
</table>
方法:
var filterFunc = function ( sData )
{
return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
};
$(document).ready
(
function()
{
$('#search').dataTable
(
{
aoColumns:[
{
'aTargets': [1],
'mData': function(source, type, val){
if (type === 'set') {
source[1] = new Object()
source[1].value = val;
source[1].value_display = val;
source.value_filter = val=="" ? "" : filterFunc(val);
return;
}
else if (type === 'display') {
return source[1].value_display;
}
else if (type === 'filter') {
return source.value_filter;
}
// 'sort', 'type' and undefined all just use the integer
return source[1].value;
}
},
{
'aTargets': [2],
'mData': function(source, type, val){
if (type === 'set') {
source[2] = new Object()
source[2].value = val;
source[2].value_display = val;
source.value_filter = val=="" ? "" : filterFunc(val);
return;
}
else if (type === 'display') {
return source[2].value_display;
}
else if (type === 'filter') {
return source.value_filter;
}
// 'sort', 'type' and undefined all just use the integer
return source[2].value;
}
},
]
}
);
}
);
参考:
http://www.datatables.net/forums/discussion/comment/43333
http://stackoverflow.com/questions/16783202/how-to-search-only-text-in-jquery-datatables