繁体   English   中英

如何从过滤数据表 jQuery 中删除 html 部分

[英]How to remove html part from filtering datatable jQuery

我使用数据表库,但遇到问题,我有过滤系统,如果在<td>中我有一些 html 代码,例如: <a hreff="#">TD name</a>我将有在 html 的部分列中:

在 JSFiddle 中,如果您将 select站代码 > 创建过滤器,您将在过滤结果中看到 HTML 代码。

图片

您可以在此处查看代码示例。

我需要如何从拟合结果中删除 html 代码,我该怎么做?

替换 td 中的 html 标签并绘制它。

render: function ( data, type, row, meta ) {
  return data.replace(/<(\/)?([a-zA-Z]*)(\s[a-zA-Z]*=[^>]*)?(\s)*(\/)?>/g, '');
}

添加您的 function addSpliting

function addSpliting(val) {
  if(val != '') {
  
  $("#test1").DataTable({
    destroy: true,
    searchPanes: {
      layout: 'columns-4',
    },
    columnDefs: [{
      searchPanes: {
        show: true,
      },
      targets: '_all',
      render: function ( data, type, row, meta ) {
        return data.replace(/<(\/)?([a-zA-Z]*)(\s[a-zA-Z]*=[^>]*)?(\s)*(\/)?>/g, '');
      }
    }],
    dom: 'Pfrtip'
  });
  $('.dtsp-searchPanes').children().each(function(i, obj){
            if(!val.includes(i)) $(this).hide();
    else $(this).show();

});

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM