我正在尝试格式化数据在 jquery DataTable 中的显示方式。
如果文本很长,我会像下面这样 chop 它:
{
"data": "col1", "render": function (data, type, row) {
if (type === 'display' && data != null) {
data = data.replace(/<(?:.|\\n)*?>/gm, '');
data = data.split("; ").join("<br/>");
if (data.length > 85) {
return '<span class=\"show-ellipsis\" title="'+data+'">' + data.substr(0, 85) + '</span><span class=\"no-show\">' + data.substr(85) + '</span>';
} else {
return data;
}
} else {
return data;
}
}
},
并使用以下 CSS 和 jquery UI 工具提示。
CSS
span.no-show {
display: none;
}
span.show-ellipsis:after {
content: "...";
}
<小时/>
jQuery UI 工具提示
<script>
$(function () {
$(document).tooltip({
items: 'span.show-ellipsis',
content: function () {
return $(this).attr('title');
},
position: {
my: "center bottom",
at: "center top-10",
collision: "flip",
using: function (position, feedback) {
$(this).addClass(feedback.vertical)
.css(position);
}
}
});
});
<小时/>
这样它就可以很好地显示在数据表中,
上面的截图有<hr>
而不是<br/>
替换方法中的标记,但行为保持不变。如果我替换为 \n
则效果很好。当我尝试导出 pdf 时,数据会重复。特别是 data.substr(85) 部分。
我做错了什么?
谢谢
最佳答案
好的,在你的按钮中
extend: 'pdfHtml5',
exportOptions: {
orthogonal: 'export',
}
在您的专栏中:
render: function (data, type, row) {
return type === 'export' ? row.Descripcion: "";
}
关于javascript - HTML 标题中的 <br/> 标记破坏了 jQuery DataTables 中的 pdfmake 导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53299077/