浏览代码

Feature/5073 (#5091)

* Added a new option to the getData method to get the formatted values

* Changed the way to check if a column exists

* code style

Co-authored-by: zhixin <wenzhixin2010@gmail.com>
Dustin Utecht 5 年之前
父节点
当前提交
69d6aa2d34
共有 2 个文件被更改,包括 14 次插入0 次删除
  1. 1 0
      site/docs/api/methods.md
  2. 13 0
      src/bootstrap-table.js

+ 1 - 0
site/docs/api/methods.md

@@ -188,6 +188,7 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
   * `useCurrentPage`: if set to true the method will return the data only in the current page.
   * `includeHiddenRows`: if set to true the method will include the hidden rows.
   * `unfiltered`: if set to true the method will include all data (unfiltered).
+  * `formatted`: get the formatted value from the defined [formatter](https://bootstrap-table.com/docs/api/column-options/#formatter).
 
 - **Example:** [Get Data](https://examples.bootstrap-table.com/#methods/getData.html)
 

+ 13 - 0
src/bootstrap-table.js

@@ -2127,6 +2127,19 @@ class BootstrapTable {
       })
     }
 
+    if (params && params.formatted) {
+      data.forEach((row) => {
+        for (const [key, value] of Object.entries(row)) {
+          const column = this.columns[this.fieldsColumnsIndex[key]]
+          if (!column) {
+            return
+          }
+
+          row[key] = Utils.calculateObjectValue(column, this.header.formatters[column.fieldIndex], [value, row, row.index, column.field], value)
+        }
+      })
+    }
+
     return data
   }