Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getData method invocation with the formatted detail parameter set to true returns formatted data for only the first column of every row #7500

Closed
Darc-Charlie opened this issue Sep 16, 2024 · 1 comment · Fixed by #7523
Labels
Bug Issues which are marked as Bug

Comments

@Darc-Charlie
Copy link
Contributor

Bootstraptable version(s) affected

1.23.0+

Description

When getData is called with the formatted parameter set to true, not only does it return the formatted data for only the first column of every row, but the {"column1key":"column1data","column2key":"column2data"} structure of each row item in the array was lost.

Example(s)

Before Bug v1.22.6
https://live.bootstrap-table.com/code/Darc-Charlie/18173

With Bug v1.23.0
https://live.bootstrap-table.com/code/Darc-Charlie/18172

Possible Solutions

The issue seems to stem from this commit:
5c1da3b under this PR #7365.

My suggestion for a fix: accumulate the key and formatted values for each found column into an object. Then return that object as the mapped value of the current row.

    if (params && params.formatted) {
      return data.map(row => {
+       const formattedColumnData = {};
        for (const [key, value] of Object.entries(row)) {
          const column = this.columns[this.fieldsColumnsIndex[key]]

          if (!column) {
            continue
          }

-         return Utils.calculateObjectValue(column, this.header.formatters[column.fieldIndex],
            [value, row, row.index, column.field], value)
+        formattedColumnData[key] = Utils.calculateObjectValue(column, this.header.formatters[column.fieldIndex],
            [value, row, row.index, column.field], value)
        }
+       return formattedColumnData;
      })
    }

Additional Context

No response

@Darc-Charlie Darc-Charlie added the Bug Issues which are marked as Bug label Sep 16, 2024
@wenzhixin
Copy link
Owner

PR is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues which are marked as Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants