【问题标题】:DataTables export options: strip html from table headsDataTables 导出选项:从表头中剥离 html
【发布时间】:2016-09-27 13:21:47
【问题描述】:

我正在使用 DataTables 1.10+。我需要从表头中删除一些元素,因此它们在导出的文件(xml、pdf、打印...)中不存在。

在这个DataTables example 中,展示了如何处理正文数据。问题是我不能对标题数据做同样的事情。

  var buttonCommon = {
    'exportOptions': {
      'format': {
        'header': function( thead, data, start, end, display ) { //'header' instead of 'body'
          return thead.replace(/X/g, ''); //Trying to remove X in every th
        }
      }          
    }
  };

PDF 文件只显示表格行,没有任何thead

我做错了什么? header函数应该使用其他参数吗?

我在 datatables.net 中找不到任何关于 format 的文档,只有上面链接的示例。

任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: javascript datatables export


    【解决方案1】:

    它必须工作,也许你在其他地方犯了一个错误。

    试试这个:

    var buttonCommon = {
        exportOptions : {
            format : {
                header : function (data, column, row) {
                    return data.replace(/X/g, '');
                }
            }
        }
    };
    

        <thead>
            <tr>
                <th>Name X</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
    

    PDF 结果:

    jsfiddle 上的示例

    【讨论】:

    • 你说得对,在我的代码中data 也返回了 html 标签,并且它在某种程度上被替换破坏了(还有比我想象的更多的东西 ^^')。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 2012-12-05
    • 2012-09-30
    • 1970-01-01
    • 2022-12-27
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    相关资源
    最近更新 更多