Browse Source

Merge pull request #4945 from wenzhixin/fix/4944

Added noeditFormatter editable function support
文翼 5 years ago
parent
commit
e6a1762175

+ 5 - 5
site/docs/extensions/editable.md

@@ -37,7 +37,7 @@ Use Plugin: [x-editable](https://github.com/vitalets/x-editable)
 - **type:** `Boolean`
 
 - **Detail:**
-    
+
     Set `true` to use always the formatter, even if the column was already edited.
 
 - **Default:** `false`
@@ -73,14 +73,14 @@ Use Plugin: [x-editable](https://github.com/vitalets/x-editable)
   </table>
   {% endhighlight %}
 
-  You can use `noeditFormatter` to disable the editable column, for example:
+  You can use `noEditFormatter` to disable the editable column, for example:
 
   {% highlight javascript %}
   {
     editable: {
-      noeditFormatter (value, row, index) {
-        if (value === 'noedit') {
-          return true
+      noEditFormatter (value, row, index) {
+        if (value === 'noEdit') {
+          return 'No Edit'
         }
         return false
       }

+ 8 - 5
src/extensions/editable/bootstrap-table-editable.js

@@ -77,19 +77,22 @@ $.BootstrapTable = class extends $.BootstrapTable {
           editableDataMarkup.push(` ${key}="${value}"`)
         })
 
-        let _dont_edit_formatter = false
-        if (column.editable.hasOwnProperty('noeditFormatter')) {
-          _dont_edit_formatter = column.editable.noeditFormatter(value, row, index)
+        let noEditFormatter = false
+        const editableOpts = Utils.calculateObjectValue(column,
+          column.editable, [index, row], {})
+
+        if (editableOpts.hasOwnProperty('noEditFormatter')) {
+          noEditFormatter = editableOpts.noEditFormatter(value, row, index)
         }
 
-        if (_dont_edit_formatter === false) {
+        if (noEditFormatter === false) {
           return `<a href="javascript:void(0)"
             data-name="${column.field}"
             data-pk="${row[this.options.idField]}"
             data-value="${result}"
             ${editableDataMarkup.join('')}></a>`
         }
-        return _dont_edit_formatter
+        return noEditFormatter
       }
     })
   }