Browse Source

added a new column option "alwaysUseFormatter" to always use the (#4896)

formatter even if the column was already edited

Co-authored-by: Dennis Hernández <dennishernandezvargas@gmail.com>
Dustin Utecht 5 years ago
parent
commit
af0961259e

+ 12 - 0
site/docs/extensions/editable.md

@@ -30,6 +30,18 @@ Use Plugin: [x-editable](https://github.com/vitalets/x-editable)
 
 ## Column options
 
+### alwaysUseFormatter
+
+- **Attribute:** `data-always-use-formatter`
+
+- **type:** `Boolean`
+
+- **Detail:**
+    
+    Set `true` to use always the formatter, even if the column was already edited.
+
+- **Default:** `false`
+
 ### editable
 
 - **Attribute:** `data-editable`

+ 6 - 2
src/extensions/editable/bootstrap-table-editable.js

@@ -21,6 +21,10 @@ $.extend($.fn.bootstrapTable.defaults, {
   }
 })
 
+$.extend($.fn.bootstrapTable.columnDefaults, {
+  alwaysUseFormatter: false
+})
+
 $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
   'editable-init.bs.table': 'onEditableInit',
   'editable-save.bs.table': 'onEditableSave',
@@ -60,7 +64,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
       column.formatter = (value, row, index) => {
         let result = Utils.calculateObjectValue(column, column._formatter, [value, row, index], value)
         result = typeof result === 'undefined' || result === null ? this.options.undefinedText : result
-        if (this.options.uniqueId !== undefined) {
+        if (this.options.uniqueId !== undefined && !column.alwaysUseFormatter) {
           const uniqueId = Utils.getItemField(row, this.options.uniqueId, false)
           if ($.inArray(column.field + uniqueId, this.editedCells) !== -1) {
             result = value
@@ -124,7 +128,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
         const row = data[rowIndex]
         const oldValue = row[column.field]
 
-        if (this.options.uniqueId !== undefined) {
+        if (this.options.uniqueId !== undefined && !column.alwaysUseFormatter) {
           const uniqueId = Utils.getItemField(row, this.options.uniqueId, false)
           if ($.inArray(column.field + uniqueId, this.editedCells) === -1) {
             this.editedCells.push(column.field + uniqueId)