gpt4 book ai didi

javascript - 数据表打印复杂表头打印预览

转载 作者:太空狗 更新时间:2023-10-29 14:17:05 25 4
gpt4 key购买 nike

嗨,我正在使用数据表,它很棒,但我遇到了像这样的复杂 header 中的问题

<thead>
<tr><td>some text</td></tr>
<tr><td>some text</td></tr>
</thead>

现在显示页面是这样的 enter image description here当我点击打印预览时,我得到了这样的结果 enter image description here

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>';

它只是在 thead 中添加最后一个 tr但我无法将第一个 tr 与打印预览一起使用非常感谢

这是一个 jsfiddle ex当您预览表格时,它会在 thead 处显示拖行但在打印预览中它只显示在 tr 上

enter link description here

最佳答案

this 中所述主题来自 Datatables website ,此功能尚不可用。

关于javascript - 数据表打印复杂表头打印预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55294594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com