ソースを参照

Merge pull request #5085 from wenzhixin/feature/5000

Added the methods "collapseRowByUniqueId" and "expandRowByUniqueId"
文翼 5 年 前
コミット
60799abf81
3 ファイル変更41 行追加1 行削除
  1. 20 0
      site/docs/api/methods.md
  2. 20 0
      src/bootstrap-table.js
  3. 1 1
      src/constants/index.js

+ 20 - 0
site/docs/api/methods.md

@@ -81,6 +81,16 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
 - **Example:** [Expand/Collapse Row](https://examples.bootstrap-table.com/#methods/expand-collapse-row.html)
 
+## collapseRowByUniqueId
+
+- **Parameter:** `uniqueId`
+
+- **Detail:**
+
+  Collapse the row that has the `uniqueId` passed by parameter if the detail view option is set to `true`.
+
+- **Example:** [Expand/Collapse Row by uniqueId](https://examples.bootstrap-table.com/#methods/expand-collapse-row-by-uniqueid.html)
+
 ## destroy
 
 - **Parameter:** `undefined`
@@ -111,6 +121,16 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
 - **Example:** [Expand/Collapse Row](https://examples.bootstrap-table.com/#methods/expand-collapse-row.html)
 
+## expandRowByUniqueId
+
+- **Parameter:** `uniqueId`
+
+- **Detail:**
+
+  Expand the row that has the `uniqueId` passed by parameter if the detail view option is set to `true`.
+
+- **Example:** [Expand/Collapse Row by uniqueId](https://examples.bootstrap-table.com/#methods/expand-collapse-row-by-uniqueid.html)
+
 ## filterBy
 
 - **Parameter:**

+ 20 - 0
src/bootstrap-table.js

@@ -2861,6 +2861,16 @@ class BootstrapTable {
     this.trigger('expand-row', index, row, $element)
   }
 
+  expandRowByUniqueId (uniqueId) {
+    const row = this.getRowByUniqueId(uniqueId)
+
+    if (!row) {
+      return
+    }
+
+    this.expandRow(this.data.indexOf(row))
+  }
+
   collapseRow (index) {
     const row = this.data[index]
     const $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"][data-has-detail-view]', index))
@@ -2876,6 +2886,16 @@ class BootstrapTable {
     $tr.next().remove()
   }
 
+  collapseRowByUniqueId (uniqueId) {
+    const row = this.getRowByUniqueId(uniqueId)
+
+    if (!row) {
+      return
+    }
+
+    this.collapseRow(this.data.indexOf(row))
+  }
+
   expandAllRows () {
     const trs = this.$body.find('> tr[data-index][data-has-detail-view]')
     for (let i = 0; i < trs.length; i++) {

+ 1 - 1
src/constants/index.js

@@ -463,7 +463,7 @@ const METHODS = [
   'scrollTo', 'getScrollPosition',
   'selectPage', 'prevPage', 'nextPage',
   'toggleDetailView',
-  'expandRow', 'collapseRow',
+  'expandRow', 'collapseRow', 'expandRowByUniqueId', 'collapseRowByUniqueId',
   'expandAllRows', 'collapseAllRows',
   'updateColumnTitle', 'updateFormatText'
 ]