ソースを参照

Allow different x-editable configuration per table row (#3940)

Karel Kozlik 7 年 前
コミット
118b2c6fc6

+ 3 - 1
src/extensions/editable/README.md

@@ -20,8 +20,10 @@ Use Plugin: [x-editable](https://github.com/vitalets/x-editable)
 
 
 ### editable
 ### editable
 
 
-* type: Object
+* type: Object or Function
 * description: Configuration of x-editable. Full list of options: http://vitalets.github.io/x-editable/docs.html#editable
 * description: Configuration of x-editable. Full list of options: http://vitalets.github.io/x-editable/docs.html#editable
+* If it is type of Function, it is called with params: index, row, element for
+  each row of the table. It should return Object of the x-editable configuration.
 * default: `undefined`
 * default: `undefined`
 
 
 All options can be defined via `data-editable-*` HTML attributes. Table wide options are used for every column but can be overridden:
 All options can be defined via `data-editable-*` HTML attributes. Table wide options are used for every column but can be overridden:

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

@@ -111,6 +111,20 @@
                 return;
                 return;
             }
             }
 
 
+            var data = that.getData();
+
+            that.$body.find('a[data-name="' + column.field + '"]').each(function(i, element){
+                var $element = $(element);
+                var $tr = $element.closest('tr');
+                var index = $tr.data('index');
+                var row = data[index];
+
+                var editableOpts = $.fn.bootstrapTable.utils.calculateObjectValue(column, column.editable, [index, row, $element], {});
+
+                $element.editable(editableOpts);
+            });
+
+
             that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
             that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
                 .off('save').on('save', function(e, params) {
                 .off('save').on('save', function(e, params) {
                     var data = that.getData(),
                     var data = that.getData(),