浏览代码

dont apply the formatter if the column was edited (#4859)

* dont apply the formatter if the column was edited

* renamed variable and check if the uniqueId is set
Dustin Utecht 5 年之前
父节点
当前提交
f7da59add5
共有 1 个文件被更改,包括 14 次插入0 次删除
  1. 14 0
      src/extensions/editable/bootstrap-table-editable.js

+ 14 - 0
src/extensions/editable/bootstrap-table-editable.js

@@ -36,6 +36,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
       return
     }
 
+    this.editedCells = []
     $.each(this.columns, (i, column) => {
       if (!column.editable) {
         return
@@ -59,6 +60,12 @@ $.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) {
+          const uniqueId = Utils.getItemField(row, this.options.uniqueId, false)
+          if ($.inArray(column.field + uniqueId, this.editedCells) !== -1) {
+            result = value
+          }
+        }
 
         $.each(column, processDataOptions)
 
@@ -117,6 +124,13 @@ $.BootstrapTable = class extends $.BootstrapTable {
         const row = data[rowIndex]
         const oldValue = row[column.field]
 
+        if (this.options.uniqueId !== undefined) {
+          const uniqueId = Utils.getItemField(row, this.options.uniqueId, false)
+          if ($.inArray(column.field + uniqueId, this.editedCells) === -1) {
+            this.editedCells.push(column.field + uniqueId)
+          }
+        }
+
         $this.data('value', submitValue)
         row[column.field] = submitValue
         this.trigger('editable-save', column.field, row, rowIndex, oldValue, $this)