ソースを参照

Merge branch 'develop' into hotfix/fix-filter-control

Dennis Hernández 5 年 前
コミット
9816ca8d57

+ 2 - 2
site/docs/api/table-options.md

@@ -1419,9 +1419,9 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Detail:**
 
-  Defines the column sort order, can only be `'asc'` or `'desc'`.
+  Defines the column sort order, can only be `'none'`, `'asc'` or `'desc'`.
 
-- **Default:** `'asc'`
+- **Default:** `'none'`
 
 - **Example:** [Sort Name Order](https://examples.bootstrap-table.com/#options/sort-name-order.html)
 

+ 4 - 1
site/docs/extensions/reorder-rows.md

@@ -126,4 +126,7 @@ if you want you can include the bootstrap-table-reorder-rows.css file to use the
 
 ### onReorderRow(reorder-row.bs.table)
 
-Fired when the row was dropped, receive as parameter the new data order.
+Fired when the row was dropped, receives two parameters:
+* The new table data
+* The dropped row
+* The row of the old position

+ 9 - 2
src/bootstrap-table.js

@@ -406,6 +406,7 @@ class BootstrapTable {
     }
 
     this.data = this.options.data
+    this.unsortedData = [...this.data]
 
     if (this.options.sidePagination === 'server') {
       return
@@ -463,6 +464,8 @@ class BootstrapTable {
           this.$el.find(`tr td:nth-child(${index + 1})`).addClass(this.options.sortClass)
         }, 250)
       }
+    } else {
+      this.data = this.unsortedData
     }
   }
 
@@ -473,7 +476,11 @@ class BootstrapTable {
     this.$header.add(this.$header_).find('span.order').remove()
 
     if (this.options.sortName === $this.data('field')) {
-      this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc'
+      const currentSortOrder = this.options.sortOrder
+      this.options.sortOrder = currentSortOrder === 'none' ? 'asc' : currentSortOrder === 'asc' ? 'desc' : 'none'
+      if (this.options.sortOrder === 'none') {
+        this.options.sortName = undefined
+      }
     } else {
       this.options.sortName = $this.data('field')
       if (this.options.rememberOrder) {
@@ -939,7 +946,7 @@ class BootstrapTable {
         }
         return false
       }) : this.data
-
+      this.unsortedData = [...this.data]
       this.initSort()
     }
   }

+ 1 - 1
src/constants/index.js

@@ -185,7 +185,7 @@ const DEFAULTS = {
   sortClass: undefined,
   silentSort: true,
   sortName: undefined,
-  sortOrder: 'asc',
+  sortOrder: 'none',
   sortStable: false,
   rememberOrder: false,
   serverSort: true,

+ 1 - 0
src/extensions/accent-neutralise/bootstrap-table-accent-neutralise.js

@@ -168,6 +168,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
         }
         return false
       }) : this.data
+      this.unsortedData = [...this.data]
     }
   }
 }

+ 65 - 49
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -206,56 +206,15 @@ $.BootstrapTable = class extends $.BootstrapTable {
             if ($.inArray(key, that.header.fields) !== -1) {
               if (value === undefined || value === null) {
                 tmpItemIsExpected = false
-              } else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
-                if (thisColumn.filterStrictSearch) {
-                  tmpItemIsExpected = value.toString().toLowerCase() === fval.toString().toLowerCase()
-                } else if (thisColumn.filterStartsWithSearch) {
-                  tmpItemIsExpected = (`${value}`).toLowerCase().indexOf(fval) === 0
-                } else {
-                  tmpItemIsExpected = (`${value}`).toLowerCase().includes(fval)
-                }
-
-                const largerSmallerEqualsRegex = /(?:(<=|=>|=<|>=|>|<)(?:\s+)?(\d+)?|(\d+)?(\s+)?(<=|=>|=<|>=|>|<))/gm
-                const matches = largerSmallerEqualsRegex.exec(fval)
-
-                if (matches) {
-                  const operator = matches[1] || `${matches[5]}l`
-                  const comparisonValue = matches[2] || matches[3]
-                  const int = parseInt(value, 10)
-                  const comparisonInt = parseInt(comparisonValue, 10)
-
-                  switch (operator) {
-                    case '>':
-                    case '<l':
-                      tmpItemIsExpected = int > comparisonInt
-                      break
-                    case '<':
-                    case '>l':
-                      tmpItemIsExpected = int < comparisonInt
-                      break
-                    case '<=':
-                    case '=<':
-                    case '>=l':
-                    case '=>l':
-                      tmpItemIsExpected = int <= comparisonInt
-                      break
-                    case '>=':
-                    case '=>':
-                    case '<=l':
-                    case '=<l':
-                      tmpItemIsExpected = int >= comparisonInt
-                      break
-                    default:
-                      break
-                  }
-                }
-
-                if (thisColumn.filterCustomSearch) {
-                  const customSearchResult = Utils.calculateObjectValue(that, thisColumn.filterCustomSearch, [fval, value, key, that.options.data], true)
-                  if (customSearchResult !== null) {
-                    tmpItemIsExpected = customSearchResult
+              } else if (typeof value === 'object') {
+                value.forEach((objectValue) => {
+                  if (tmpItemIsExpected) {
+                    return
                   }
-                }
+                  tmpItemIsExpected = that.isValueExpected(fval, objectValue, thisColumn, key)
+                })
+              } else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
+                tmpItemIsExpected = that.isValueExpected(fval, value, thisColumn, key)
               }
             }
           }
@@ -266,6 +225,63 @@ $.BootstrapTable = class extends $.BootstrapTable {
         return !itemIsExpected.includes(false)
       })
       : that.data
+
+    that.unsortedData = [...that.data]
+  }
+
+  isValueExpected (searchValue, value, column, key) {
+    let tmpItemIsExpected = false
+    if (column.filterStrictSearch) {
+      tmpItemIsExpected = value.toString().toLowerCase() === searchValue.toString().toLowerCase()
+    } else if (column.filterStartsWithSearch) {
+      tmpItemIsExpected = (`${value}`).toLowerCase().indexOf(searchValue) === 0
+    } else {
+      tmpItemIsExpected = (`${value}`).toLowerCase().includes(searchValue)
+    }
+
+    const largerSmallerEqualsRegex = /(?:(<=|=>|=<|>=|>|<)(?:\s+)?(\d+)?|(\d+)?(\s+)?(<=|=>|=<|>=|>|<))/gm
+    const matches = largerSmallerEqualsRegex.exec(searchValue)
+
+    if (matches) {
+      const operator = matches[1] || `${matches[5]}l`
+      const comparisonValue = matches[2] || matches[3]
+      const int = parseInt(value, 10)
+      const comparisonInt = parseInt(comparisonValue, 10)
+
+      switch (operator) {
+        case '>':
+        case '<l':
+          tmpItemIsExpected = int > comparisonInt
+          break
+        case '<':
+        case '>l':
+          tmpItemIsExpected = int < comparisonInt
+          break
+        case '<=':
+        case '=<':
+        case '>=l':
+        case '=>l':
+          tmpItemIsExpected = int <= comparisonInt
+          break
+        case '>=':
+        case '=>':
+        case '<=l':
+        case '=<l':
+          tmpItemIsExpected = int >= comparisonInt
+          break
+        default:
+          break
+      }
+    }
+
+    if (column.filterCustomSearch) {
+      const customSearchResult = Utils.calculateObjectValue(this, column.filterCustomSearch, [searchValue, value, key, this.options.data], true)
+      if (customSearchResult !== null) {
+        tmpItemIsExpected = customSearchResult
+      }
+    }
+
+    return tmpItemIsExpected
   }
 
   initColumnSearch (filterColumnsDefaults) {

+ 1 - 1
src/extensions/reorder-rows/bootstrap-table-reorder-rows.js

@@ -90,6 +90,6 @@ $.BootstrapTable = class extends $.BootstrapTable {
     this.options.onReorderRowsDrop(droppedRow)
 
     // Call the event reorder-row
-    this.trigger('reorder-row', newData)
+    this.trigger('reorder-row', newData, draggingRow, droppedRow)
   }
 }

+ 1 - 0
src/extensions/toolbar/bootstrap-table-toolbar.js

@@ -372,6 +372,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
       }
       return true
     }) : this.data
+    this.unsortedData = [...this.data]
   }
 
   onColumnAdvancedSearch (e) {