datatables搜索时如何过滤链接中<a>标签--[多列时]

两种方案:

方案一:

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值