ソースを参照

Merge pull request #2941 from ibraheemhlaiyil/patch-3

feat(js): add 'detailFilter' option
文翼 8 年 前
コミット
977db5f822
2 ファイル変更18 行追加4 行削除
  1. 7 0
      docs/_i18n/en/documentation/table-options.md
  2. 11 4
      src/bootstrap-table.js

+ 7 - 0
docs/_i18n/en/documentation/table-options.md

@@ -448,6 +448,13 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
         <td>Format your detail view when <code>detailView</code> is set to <code>true</code>. Return a String and it will be appended into the detail view cell, optionally render the element directly using the third parameter which is a jQuery element of the target cell.</td>
     </tr>
     <tr>
+        <td>detailFilter</td>
+        <td>data-detail-filter</td>
+        <td>Function</td>
+        <td>function(index, row) {<br>return true;<br>}</td>
+        <td>Enable expansion per row when <code>detailView</code> is set to <code>true</code>. Return <code>true</code> and the row will be enabled for expansion, return <code>false</code> and expansion for the row will be disabled. Default function returns <code>true</code> to enable expansion for all rows.</td>
+    </tr>
+    <tr>
         <td>searchAlign</td>
         <td>data-search-align</td>
         <td>String</td>

+ 11 - 4
src/bootstrap-table.js

@@ -340,6 +340,9 @@
         detailFormatter: function (index, row) {
             return '';
         },
+        detailFilter: function (index, row) {
+            return true;
+        },
         trimOnSearch: true,
         clickToSelect: false,
         singleSelect: false,
@@ -1658,11 +1661,15 @@
         }
 
         if (!this.options.cardView && this.options.detailView) {
-            html.push('<td>',
-                '<a class="detail-icon" href="#">',
+            html.push('<td>');
+
+            if (calculateObjectValue(null, this.options.detailFilter, [i, item])) {
+                html.push('<a class="detail-icon" href="javascript:">',
                 sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.detailOpen),
-                '</a>',
-                '</td>');
+                '</a>');
+            }
+
+            html.push('</td>');
         }
 
         $.each(this.header.fields, function(j, field) {