Browse Source

Update rowAttributes option.

zhixin 11 years ago
parent
commit
1052fe5562
2 changed files with 16 additions and 3 deletions
  1. 12 0
      _docs/_includes/documentation/table-options.md
  2. 4 3
      src/bootstrap-table.js

+ 12 - 0
_docs/_includes/documentation/table-options.md

@@ -324,5 +324,17 @@ The table options is defined in `jQuery.fn.bootstrapTable.defaults`.
         Support classes or css.
         </td>
     </tr>
+    <tr>
+        <td>rowAttributes</td>
+        <td>data-row-attributes</td>
+        <td>Function</td>
+        <td>{}</td>
+        <td>
+        The row attribute formatter function, take two parameters: <br>
+        row: the row record data.<br>
+        index: the row index.<br>
+        Support all custom attributes.
+        </td>
+    </tr>
     </tbody>
 </table>

+ 4 - 3
src/bootstrap-table.js

@@ -888,16 +888,17 @@
                 }
             }
 
-            attributes = calculateObjectValue(this.options, this.options.rowAttributes, [item, i], attributes);
+            attributes = calculateObjectValue(this.options,
+                this.options.rowAttributes, [item, i], attributes);
 
             if (attributes) {
                 for (var key in attributes) {
-                    htmlAttributes.push(key + '="' + attributes[key] + '"')
+                    htmlAttributes.push(sprintf('%s="%s"', key, attributes[key]));
                 }
             }
 
             html.push('<tr',
-                sprintf(' %s', htmlAttributes),
+                sprintf(' %s', htmlAttributes.join(' ')),
                 sprintf(' id="%s"', item._id),
                 sprintf(' class="%s"', style.classes || item._class),
                 sprintf(' data-index="%s"', i),