浏览代码

Merge pull request #5160 from wenzhixin/feature/auto-merge-cells

Added autoMergeCells option
Dustin Utecht 5 年之前
父节点
当前提交
f522c73006
共有 4 个文件被更改,包括 38 次插入3 次删除
  1. 3 0
      CHANGELOG.md
  2. 21 2
      site/docs/api/table-options.md
  3. 3 1
      src/bootstrap-table.js
  4. 11 0
      src/utils/index.js

+ 3 - 0
CHANGELOG.md

@@ -20,6 +20,7 @@ ChangeLog
 - **New:** Added `formatted` parameter for `getData` method to get formatted data.
 - **New:** Added `formatted` parameter for `getData` method to get formatted data.
 - **New:** Added `paginationParts` option instead of `onlyInfoPagination`.
 - **New:** Added `paginationParts` option instead of `onlyInfoPagination`.
 - **New:** Added `sortReset` option to reset sort on third click.
 - **New:** Added `sortReset` option to reset sort on third click.
+- **New:** Added support for auto merge the table body cells.
 - **Update:** Fixed `updateByUniqueId` method cannot update multiple rows bug.
 - **Update:** Fixed `updateByUniqueId` method cannot update multiple rows bug.
 - **Update:** Fixed `insertRow` not write to source data array bug.
 - **Update:** Fixed `insertRow` not write to source data array bug.
 - **Update:** Fixed events bug with `detailViewIcon` option.
 - **Update:** Fixed events bug with `detailViewIcon` option.
@@ -31,6 +32,7 @@ ChangeLog
 - **Update:** Fixed table `border` bug when table is hidden.
 - **Update:** Fixed table `border` bug when table is hidden.
 - **Update:** Fixed `showRow` method show all hidden rows bug.
 - **Update:** Fixed `showRow` method show all hidden rows bug.
 - **Remove:** Removed the `onlyInfoPagination` option.
 - **Remove:** Removed the `onlyInfoPagination` option.
+- **Remove:** Removed accent neutralise extension and moved it to core.
 
 
 #### Extensions
 #### Extensions
 
 
@@ -49,6 +51,7 @@ ChangeLog
 - **Update(accent-neutralise):** Fixed comparison with arrays.
 - **Update(accent-neutralise):** Fixed comparison with arrays.
 - **Update(cookie):** Updated cookie columns to always visible when `switchable` is `false`.
 - **Update(cookie):** Updated cookie columns to always visible when `switchable` is `false`.
 - **Update(cookie):** Fixed cookie value from existing options bug.
 - **Update(cookie):** Fixed cookie value from existing options bug.
+- **Update(copy-rows):** Fixed copy rows bug with fixed-column.
 - **Update(editable):** Fixed not handle quotation marks bug.
 - **Update(editable):** Fixed not handle quotation marks bug.
 - **Update(editable):** Updated `noeditFormatter` to `noEditFormatter`.
 - **Update(editable):** Updated `noeditFormatter` to `noEditFormatter`.
 - **Update(export):** Fixed export error with `maintainMetaData` and `clientSidePagination`.
 - **Update(export):** Fixed export error with `maintainMetaData` and `clientSidePagination`.

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

@@ -279,6 +279,25 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 
   The data to be loaded.
   The data to be loaded.
 
 
+  If in the data has `_<field>_rowspan` or `_<field>_colspan` property, then will merge cells auto, for example:
+  ```js
+  $table.bootstrapTable({
+    data: [
+      {
+        id: 1,
+        name: 'Item 1',
+        _name_rowspan: 2,
+        price: '$1'
+      },
+      {
+        id: 2,
+        price: '$2'
+      }
+    ]
+  })
+  ```
+  If use this feature, the `data` is required to ensure that the format is correct.
+
 - **Default:** `[]`
 - **Default:** `[]`
 
 
 - **Example:** [From Data](https://examples.bootstrap-table.com/#welcomes/from-data.html)
 - **Example:** [From Data](https://examples.bootstrap-table.com/#welcomes/from-data.html)
@@ -621,7 +640,7 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
   * loadingMessage: the `formatLoadingMessage` locale.
   * loadingMessage: the `formatLoadingMessage` locale.
 
 
 - **Default:**
 - **Default:**
-  ```
+  ```js
   function (loadingMessage) {
   function (loadingMessage) {
     return '<span class="loading-wrap">' +
     return '<span class="loading-wrap">' +
       '<span class="loading-text">' +
       '<span class="loading-text">' +
@@ -1051,7 +1070,7 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 
 - **Default:** `false`
 - **Default:** `false`
 
 
-- **Example:** [Accent Neutralise](https://examples.bootstrap-table.com/#options/search-align.html)
+- **Example:** [Search Accent Neutralise](https://examples.bootstrap-table.com/#options/search-accent-neutralise.html)
 
 
 ## searchAlign
 ## searchAlign
 
 

+ 3 - 1
src/bootstrap-table.js

@@ -1377,7 +1377,7 @@ class BootstrapTable {
       let title_ = ''
       let title_ = ''
       const column = this.columns[j]
       const column = this.columns[j]
 
 
-      if (this.fromHtml && typeof value_ === 'undefined') {
+      if ((this.fromHtml || this.autoMergeCells) && typeof value_ === 'undefined') {
         if ((!column.checkbox) && (!column.radio)) {
         if ((!column.checkbox) && (!column.radio)) {
           return
           return
         }
         }
@@ -1520,6 +1520,8 @@ class BootstrapTable {
     const trFragments = $(document.createDocumentFragment())
     const trFragments = $(document.createDocumentFragment())
     let hasTr = false
     let hasTr = false
 
 
+    this.autoMergeCells = Utils.checkAutoMergeCells(data.slice(this.pageFrom - 1, this.pageTo))
+
     for (let i = this.pageFrom - 1; i < this.pageTo; i++) {
     for (let i = this.pageFrom - 1; i < this.pageTo; i++) {
       const item = data[i]
       const item = data[i]
       const tr = this.initRow(item, i, data, trFragments)
       const tr = this.initRow(item, i, data, trFragments)

+ 11 - 0
src/utils/index.js

@@ -338,5 +338,16 @@ export default {
 
 
   hasDetailViewIcon (options) {
   hasDetailViewIcon (options) {
     return options.detailView && options.detailViewIcon && !options.cardView
     return options.detailView && options.detailViewIcon && !options.cardView
+  },
+
+  checkAutoMergeCells (data) {
+    for (const row of data) {
+      for (const key of Object.keys(row)) {
+        if (key.startsWith('_') && (key.endsWith('_rowspan') || key.endsWith('_colspan'))) {
+          return true
+        }
+      }
+    }
+    return false
   }
   }
 }
 }