Skip to content

Commit

Permalink
Merge pull request #7160 from wenzhixin/fix/7157
Browse files Browse the repository at this point in the history
Fixed print bug when field is not set
  • Loading branch information
wenzhixin authored Jan 20, 2024
2 parents ebaf001 + cafdc97 commit 89aada0
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/extensions/print/bootstrap-table-print.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand All @@ -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)}
Expand Down Expand Up @@ -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>')
Expand All @@ -225,7 +228,6 @@ $.BootstrapTable = class extends $.BootstrapTable {
}
}


html.push('</tr>')
}

Expand All @@ -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] || '')

Expand Down

0 comments on commit 89aada0

Please sign in to comment.