【问题标题】:Efficient way for printing only ag-grid data without pagination or any other content仅打印没有分页或任何其他内容的 ag-grid 数据的有效方法
【发布时间】:2020-06-17 01:18:03
【问题描述】:

我正在尝试仅打印 ag-grid 数据,例如 Data-Table print 中的打印按钮

1-我尝试了 ngx-print,但它不适用于 angular 8。

2-我尝试了ag-grid-Example的官方方式 但我认为它在打印时显示分页和其他页面内容也不是一种有效的方式。

我按照以下步骤尝试了带有角度的print-This 插件:

1- 由npm 安装它 2-调用节点 angular.json 中的 .js 文件(包含您要在系统中使用的所有插件的文件) 但是,它仍然无法将 .printThis() 识别为函数。

我不知道如何打印唯一的ag-grid数据而没有页面的其他内容,为什么没有ag-grid的内置功能,例如DataTable插件?!!!

【问题讨论】:

    标签: javascript printing ag-grid ag-grid-angular


    【解决方案1】:

    2-我尝试了来自 ag-grid-Example 的官方方式但我认为不是 一种有效的方式还有它的显示分页和另一个页面内容 打印时。

    但这已经是打印所有数据的有效且预期的方式(没有网格分页)。

    如果您想隐藏其他内容(无法理解 without another content of the page 是什么意思)- 需要预先呈现这些数据(或至少准备浏览器打印方法)

    更新

    我检查了datatable 解决方案,基本上它就像我说的那样,他们只是准备了在新的window 上制作datatable 内容的函数,以便与其他所有内容隔离,然后执行print() 方法。

    这里是part of their code(仅供理解):

    // Construct a table for printing
    var html = '<table class="'+dt.table().node().className+'">';
    
    if ( config.header ) {
        html += '<thead>'+ addRow( data.header, 'th' ) +'</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>';
    
    ...
    
    // Allow stylesheets time to load
    var autoPrint = function () {
        if ( config.autoPrint ) {
            win.print(); // blocking - so close will not
            win.close(); // execute until this is done
        }
    };
    

    另外,我尝试使用hiding elements,这也是可能的,但这样就需要关心可见性和覆盖。

    【讨论】:

    • 没有效率的方法为什么我要在没有分页的情况下制作 ag-grid 以使用打印功能?为什么要进行调整大小操作以打印功能?我的客户想要分页和打印?!查看 dataTable 中的打印功能,您就会明白我所说的高效方式的意思!
    • @un.spike 这看起来像是评论,而不是答案!
    • @un.spike 如果您尝试了this link 中的示例,您会发现 ag-grid 已经没有分页,当您打印时,您会发现打印按钮出现在打印预览中! !!
    • @user3189162 是的,我遇到了你的问题,这就是为什么在答案中添加详细信息
    • @un.spike 谢谢你的帮助,但我有另一个问题,那么你附加的代码部分我应该放在哪里?它是否保持了 ag-grid 的风格?
    猜你喜欢
    • 2019-06-14
    • 1970-01-01
    • 2017-06-28
    • 2018-08-07
    • 2018-06-05
    • 2014-11-21
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多