浏览代码

add Table property: rowAttribute, for adding custom table row attributes

Ice5050 11 年之前
父节点
当前提交
c57df0c3ea
共有 1 个文件被更改,包括 14 次插入1 次删除
  1. 14 1
      src/bootstrap-table.js

+ 14 - 1
src/bootstrap-table.js

@@ -156,6 +156,8 @@
 
 
         rowStyle: function (row, index) {return {};},
         rowStyle: function (row, index) {return {};},
 
 
+        rowAttributes: function (row, index) {return {};},
+
         formatLoadingMessage: function () {
         formatLoadingMessage: function () {
             return 'Loading, please wait…';
             return 'Loading, please wait…';
         },
         },
@@ -874,7 +876,9 @@
         for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
         for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
             var item = data[i],
             var item = data[i],
                 style = {},
                 style = {},
-                csses = [];
+                csses = [],
+                attributes = {},
+                htmlAttributes = [];
 
 
             style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
             style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
 
 
@@ -884,7 +888,16 @@
                 }
                 }
             }
             }
 
 
+            attributes = calculateObjectValue(this.options, this.options.rowAttributes, [item, i], attributes);
+
+            if (attributes) {
+                for (var key in attributes) {
+                    htmlAttributes.push(key + '="' + attributes[key] + '"')
+                }
+            }
+
             html.push('<tr',
             html.push('<tr',
+                sprintf(' %s', htmlAttributes),
                 sprintf(' id="%s"', item._id),
                 sprintf(' id="%s"', item._id),
                 sprintf(' class="%s"', style.classes || item._class),
                 sprintf(' class="%s"', style.classes || item._class),
                 sprintf(' data-index="%s"', i),
                 sprintf(' data-index="%s"', i),