Browse Source

imroved documentation, added default value and linting

Dustin Utecht 6 years ago
parent
commit
644fd97545
2 changed files with 29 additions and 28 deletions
  1. 1 1
      site/docs/api/column-options.md
  2. 28 27
      src/bootstrap-table.js

+ 1 - 1
site/docs/api/column-options.md

@@ -403,7 +403,7 @@ The column options is defined in `jQuery.fn.bootstrapTable.columnDefaults`.
 
 - **Detail:**
 
-  Format your detail view when detailView and detailViewByClick is set to true. 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.
+  Format your detail view when `detailView` and `detailViewByClick` is set to `true`. 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.
   
   Fallback is the detail-formatter of the table.
 

+ 28 - 27
src/bootstrap-table.js

@@ -559,6 +559,7 @@
     footerFormatter: undefined,
     events: undefined,
     sorter: undefined,
+    detailFormatters: [],
     sortName: undefined,
     cellStyle: undefined,
     searchable: true,
@@ -2001,19 +2002,19 @@
           }
         }
 
-        if(
-            type === 'click' &&
+        if (
+          type === 'click' &&
             this.options.detailViewByClick
-        ){
-            const $detailIcon = $tr.find('.detail-icon')
-            let detailFormatter = this.header.detailFormatters[index - 1] || undefined
-            this.toggleDetailView($detailIcon, detailFormatter);
+        ) {
+          const $detailIcon = $tr.find('.detail-icon')
+          const detailFormatter = this.header.detailFormatters[index - 1] || undefined
+          this.toggleDetailView($detailIcon, detailFormatter)
         }
       })
 
       this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', e => {
         e.preventDefault()
-        this.toggleDetailView($(e.currentTarget));
+        this.toggleDetailView($(e.currentTarget))
         return false
       })
 
@@ -2071,28 +2072,28 @@
       this.trigger('post-body', data)
     }
 
-    toggleDetailView($iconElement, columnDetailFormatter) {
-        const $tr = $iconElement.parent().parent()
-        const index = $tr.data('index')
-        const row = this.data[index]
+    toggleDetailView ($iconElement, columnDetailFormatter) {
+      const $tr = $iconElement.parent().parent()
+      const index = $tr.data('index')
+      const row = this.data[index]
 
-        // remove and update
-        if ($tr.next().is('tr.detail-view')) {
-            $iconElement.html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailOpen))
-            this.trigger('collapse-row', index, row, $tr.next())
-            $tr.next().remove()
-        } else {
-            $iconElement.html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailClose))
-            $tr.after(Utils.sprintf('<tr class="detail-view"><td colspan="%s"></td></tr>', $tr.children('td').length))
-            const $element = $tr.next().find('td')
-            let detailFormatter = columnDetailFormatter || this.options.detailFormatter
-            const content = Utils.calculateObjectValue(this.options, detailFormatter, [index, row, $element], '')
-            if ($element.length === 1) {
-                $element.append(content)
-            }
-            this.trigger('expand-row', index, row, $element)
+      // remove and update
+      if ($tr.next().is('tr.detail-view')) {
+        $iconElement.html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailOpen))
+        this.trigger('collapse-row', index, row, $tr.next())
+        $tr.next().remove()
+      } else {
+        $iconElement.html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailClose))
+        $tr.after(Utils.sprintf('<tr class="detail-view"><td colspan="%s"></td></tr>', $tr.children('td').length))
+        const $element = $tr.next().find('td')
+        const detailFormatter = columnDetailFormatter || this.options.detailFormatter
+        const content = Utils.calculateObjectValue(this.options, detailFormatter, [index, row, $element], '')
+        if ($element.length === 1) {
+          $element.append(content)
         }
-        this.resetView()
+        this.trigger('expand-row', index, row, $element)
+      }
+      this.resetView()
     }
 
     initServer (silent, query, url) {