【问题标题】:Datatable fnCellRender doesn't render数据表 fnCellRender 不呈现
【发布时间】:2014-12-07 11:22:43
【问题描述】:

我正在尝试在我正在执行的函数中导出到 excel 之前渲染一些字段;

"tableTools": {
                "sSwfPath": "assets/global/plugins/data-tables/tabletools/swf/copy_csv_xls_pdf.swf",
                "aButtons": [ {
                    "sExtends": "xls",
                    "sButtonText": "Excel",
                    "fnCellRender":function(sValue,iColumn,nTr,iDataIndex){
                        console.log(sValue);
                        //console.log($(sValue));
                        return sValue;
                    }
                }, {
                    "sExtends": "print",
                    "sButtonText": lang.L_PRINT,
                    "sInfo": lang.L_PRINT_DESC,
                    "sMessage": "Metrics"
                }]
            }

所以当我取消注释时

 console.log($(sValue)); 

它只返回第一列和第二列,其中不包含任何 html 标记。但是当它找到一个带有 html 标签的值时,它就会停止。

ex - 这得到了价值

 <td class=" sorting_1">201408</td>

这不是

 <span style="text-align:right;display:block;width:100%">121.25</span>

我该如何解决?

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    为了解决这个问题,我发现将数据写入 CSV 并查看格式要容易得多,这样我就可以选择如何解析。

    当您使用fnCellRender 属性时,TableTools 将不再对 HTML 进行任何解析。我希望您会在控制台窗口中看到原始数据,其中一些是我假设的 HTML,而其他只是值。

    当它是 HTML 时,您可以使用 JQuery 来提取值或正则表达式。例如

    if ($(sValue).prop("checked")) {
           return "TRUE";
    } else {
           return "FALSE";
    }
    

    或者在你的情况下

    return $(sValue).val();
    

    我使用的一些研究:
    TableTools background and good discussion with links

    TableTools Reference API

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-08
      • 2013-12-11
      相关资源
      最近更新 更多