Datatable fnCellRender doesn't render

Datatable fnCellRender doesn't render

本文关键字:render fnCellRender doesn Datatable      更新时间:2023-09-26

>我正在尝试在导出之前渲染一些字段以在我的函数中表现出色,我就是这样做的;

"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>

我该如何解决?

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

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

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

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

或在您的情况下

return $(sValue).val();

我使用的一些研究:
表格工具背景和带链接的良好讨论

表工具参考 API