【发布时间】:2019-08-13 03:27:17
【问题描述】:
嗨,我正在使用数据表,它很棒,但我在像这样的复杂标题中遇到了问题
<thead>
<tr><td>some text</td></tr>
<tr><td>some text</td></tr>
</thead>
thead 中的第一个 tr 消失了
我打开了 datatable.js 文件,我发现了这个
var addRow = function ( d, tag ) {
var str = '<tr>';
for ( var i=0, ien=d.length ; i<ien ; i++ ) {
// null and undefined aren't useful in the print output
var dataOut = d[i] === null || d[i] === undefined ?
'' :
d[i];
var classAttr = columnClasses[i] ?
'class="'+columnClasses[i]+'"' :
'';
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
}
return str + '</tr>';
};
// Construct a table for printing
var html = '<table class="'+dt.table().node().className+'">';
html += '<thead>';
// Adding logo to the page (repeats for every page while print)
if(config.repeatingHead.logo) {
var logoPosition = (['left','right','center'].indexOf(config.repeatingHead.logoPosition) > 0) ? config.repeatingHead.logoPosition : 'right';
html += '<tr><th colspan="'+data.header.length+'" style="padding: 0;margin: 0;text-align: '+logoPosition+';"><img style="'+config.repeatingHead.logoStyle+'" src="'+config.repeatingHead.logo+'"/></th></tr>';
}
// Adding title (repeats for every page while print)
if(config.repeatingHead.title) {
html += '<tr><th colspan="'+data.header.length+'">'+config.repeatingHead.title+'</th></tr>';
}
if ( config.header ) {
html += addRow( data.header, 'th' );
}
html += '</thead>';
html += '<tbody>';
for ( var i=0, ien=data.body.length ; i<ien ; i++ ) {
html += addRow( data.body[i], 'td' );
}
html += '</tbody>';
if ( config.footer && data.footer ) {
html += '<tfoot>'+ addRow( data.footer, 'th' ) +'</tfoot>';
}
html += '</table>';
它只是在头中添加最后一个 tr 但我无法将第一个 tr 与打印预览放在一起 非常感谢
这是一个 jsfiddle ex 当您预览表格时,它在thead 处显示有拖行 但在打印预览中,它仅在广告中的 tr 上显示
【问题讨论】:
-
能否补充一下可以理解的问题和解决方案?
-
能否创建一个stack sn-p/jsFiddle来验证?
-
我在 jsfiddle 上上传示例
-
@AwarPullldozer 确实希望页眉和页脚应该在打印视图中吗?
-
是的,这就是我想要的
标签: javascript html datatable