【问题标题】:How to skip last row in datatable export option (.csv pdf options)如何跳过数据表导出选项中的最后一行(.csv pdf 选项)
【发布时间】:2016-09-13 19:45:27
【问题描述】:

我的脚本在下面。 我想跳过我在 excel 和 pdf 中的最后一行。

$('.data-grid-export').DataTable({
    dom: 'Blfrtip',
    buttons: [
        {
            extend: 'pdf',
            footer: true,
        },
        {
            extend: 'excel',
            footer: false
        }
    ]
});

【问题讨论】:

    标签: jquery excel datatable datatables pdf-generation


    【解决方案1】:

    尝试使用例如 initComplete 将类或 Id 添加到最后一行:

    initComplete : function(){
        $(".data-grid-export tr").last().addClass("notPrintable");
    }
    

    然后使用buttonsexportOptions 选项指定除具有类/id 的行之外的所有行:

    buttons:[
            {
                extend: 'pdf',
                exportOptions:{
                    rows: ':not(.notPrintable)'
                }
            }
    

    这在我的表中有效,希望对您有所帮助

    【讨论】:

      【解决方案2】:

      用户自定义选项 导出 Excel 的简单示例如下所示:

      customize: function (xlsx) {
                                          var sheet =xlsx.xl.worksheets['sheet1.xml'];
                                          $('row', sheet).filter(function () {
                                              var attr = $(this).attr('r');
                                              if (attr == $('row', sheet).length) //last row
                                                  return true;
                                              return false;
                                          }).remove();
                                 }
      

      【讨论】:

        【解决方案3】:

        DataTables row-selector 支持 jQuery 选择器,因此跳过最后一行的最简单方法是:

        {
          extend: 'pdfHtml5',
          exportOptions: {
            rows: ':not(:last)'
          }
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-03-03
          • 2018-03-09
          • 1970-01-01
          • 2022-06-24
          • 2021-05-12
          • 2016-10-15
          • 2016-10-27
          相关资源
          最近更新 更多