Browse Source

Fixed escape column option does not override table option bug.

zhixin 3 years ago
parent
commit
db9b7263cf
3 changed files with 9 additions and 4 deletions
  1. 1 1
      site/docs/api/column-options.md
  2. 2 2
      src/bootstrap-table.js
  3. 6 1
      src/utils/index.js

+ 1 - 1
site/docs/api/column-options.md

@@ -156,7 +156,7 @@ The column options is defined in `jQuery.fn.bootstrapTable.columnDefaults`.
 
   Escapes a string for insertion into HTML, replacing &, <, >, ", \`, and ' characters.
 
-- **Default:** `false`
+- **Default:** `undefined`
 
 - **Example:** [Column Escape](https://examples.bootstrap-table.com/#column-options/escape.html)
 

+ 2 - 2
src/bootstrap-table.js

@@ -1514,7 +1514,7 @@ class BootstrapTable {
     this.header.fields.forEach((field, j) => {
       const column = this.columns[j]
       let text = ''
-      let value_ = Utils.getItemField(item, field, column.escape ?? this.options.escape)
+      let value_ = Utils.getItemField(item, field, this.options.escape, column.escape)
       let value = ''
       let type = ''
       let cellStyle = {}
@@ -1794,7 +1794,7 @@ class BootstrapTable {
       const fields = this.getVisibleFields()
       const field = fields[index - Utils.getDetailViewIndexOffset(this.options)]
       const column = this.columns[this.fieldsColumnsIndex[field]]
-      const value = Utils.getItemField(item, field, column.escape ?? this.options.escape)
+      const value = Utils.getItemField(item, field, this.options.escape, column.escape)
 
       if ($td.find('.detail-icon').length) {
         return

+ 6 - 1
src/utils/index.js

@@ -364,9 +364,14 @@ export default {
     return dataAttr
   },
 
-  getItemField (item, field, escape) {
+  getItemField (item, field, escape, columnEscape = undefined) {
     let value = item
 
+    // use column escape if it is defined
+    if (typeof columnEscape !== 'undefined') {
+      escape = columnEscape
+    }
+
     if (typeof field !== 'string' || item.hasOwnProperty(field)) {
       return escape ? this.escapeHTML(item[field]) : item[field]
     }