Browse Source

Merge pull request #7160 from wenzhixin/fix/7157

Fixed print bug when field is not set
文翼 1 year ago
parent
commit
89aada0cf3
1 changed files with 12 additions and 10 deletions
  1. 12 10
      src/extensions/print/bootstrap-table-print.js

+ 12 - 10
src/extensions/print/bootstrap-table-print.js

@@ -135,9 +135,12 @@ $.BootstrapTable = class extends $.BootstrapTable {
   }
 
   doPrint (data) {
-    const _this2 = this
+    const canPrint = column => {
+      return !column.printIgnore && column.visible
+    }
+
     const formatValue = (row, i, column) => {
-      const value_ = Utils.getItemField(row, column.field, _this2.options.escape, column.escape)
+      const value_ = Utils.getItemField(row, column.field, this.options.escape, column.escape)
       const value = Utils.calculateObjectValue(column,
         column.printFormatter || column.formatter,
         [value_, row, i], value_)
@@ -153,7 +156,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
       for (const columns of columnsArray) {
         html.push('<tr>')
         for (let h = 0; h < columns.length; h++) {
-          if (!columns[h].printIgnore && columns[h].visible) {
+          if (canPrint(columns[h])) {
             html.push(
               `<th
               ${Utils.sprintf(' rowspan="%s"', columns[h].rowspan)}
@@ -211,11 +214,11 @@ $.BootstrapTable = class extends $.BootstrapTable {
           }
 
           if (
-            !columns[j].printIgnore && columns[j].visible && columns[j].field &&
-              (
-                !notRender.includes(`${i},${j}`) ||
-                rowspan > 0 && colspan > 0
-              )
+            canPrint(columns[j]) &&
+            (
+              !notRender.includes(`${i},${j}`) ||
+              rowspan > 0 && colspan > 0
+            )
           ) {
             if (rowspan > 0 && colspan > 0) {
               html.push(`<td ${Utils.sprintf(' rowspan="%s"', rowspan)} ${Utils.sprintf(' colspan="%s"', colspan)}>`, formatValue(data[i], i, columns[j]), '</td>')
@@ -225,7 +228,6 @@ $.BootstrapTable = class extends $.BootstrapTable {
           }
         }
 
-
         html.push('</tr>')
       }
 
@@ -235,7 +237,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
 
         for (const columns of columnsArray) {
           for (let h = 0; h < columns.length; h++) {
-            if (!columns[h].printIgnore && columns[h].visible) {
+            if (canPrint(columns)) {
               const footerData = Utils.trToData(columns, this.$el.find('>tfoot>tr'))
               const footerValue = Utils.calculateObjectValue(columns[h], columns[h].footerFormatter, [data], footerData[0] && footerData[0][columns[h].field] || '')