Skip to content

Commit

Permalink
Feature/sort reset (wenzhixin#5156)
Browse files Browse the repository at this point in the history
* Added sortReset option

* Update changelog
  • Loading branch information
wenzhixin authored Jul 9, 2020
1 parent 1aed7e5 commit caf0440
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ChangeLog
- **New:** Added tr `class` support for `thead`.
- **New:** Added `formatted` parameter for `getData` method to get formatted data.
- **New:** Added `paginationParts` option instead of `onlyInfoPagination`.
- **New:** Added `sortReset` option to reset sort on third click.
- **Update:** Fixed `updateByUniqueId` method cannot update multiple rows bug.
- **Update:** Fixed `insertRow` not write to source data array bug.
- **Update:** Fixed events bug with `detailViewIcon` option.
Expand All @@ -39,6 +40,7 @@ ChangeLog
- **New(export):** Added `forceHide` column option.
- **New(filter-control):** Added `filterOrderBy` column option support order by `server`.
- **New(filter-control):** Added radio support for `filterControlContainer`.
- **New(filter-control):** Added support for array filter.
- **New(filter-control):** Added `filterControlVisible` option and `toggleFilterControl` method.
- **New(filter-control):** Added `showFilterControlSwitch` option.
- **New(fixed-columns):** Added support for sticky-header.
Expand Down
18 changes: 16 additions & 2 deletions site/docs/api/table-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1419,12 +1419,26 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.

- **Detail:**

Defines the column sort order, can only be `'none'`, `'asc'` or `'desc'`.
Defines the column sort order, can only be `undefined`, `'asc'` or `'desc'`.

- **Default:** `'none'`
- **Default:** `undefined`

- **Example:** [Sort Name Order](https://examples.bootstrap-table.com/#options/sort-name-order.html)

## sortReset

- **Attribute:** `data-sort-reset`

- **Type:** `Boolean`

- **Detail:**

Set `true` to reset the sort on third click.

- **Default:** `false`

- **Example:** [Sort Reset](https://examples.bootstrap-table.com/#options/sort-reset.html)

## sortStable

- **Attribute:** `data-sort-stable`
Expand Down
12 changes: 10 additions & 2 deletions src/bootstrap-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,16 @@ class BootstrapTable {

if (this.options.sortName === $this.data('field')) {
const currentSortOrder = this.options.sortOrder
this.options.sortOrder = currentSortOrder === 'none' ? 'asc' : currentSortOrder === 'asc' ? 'desc' : 'none'
if (this.options.sortOrder === 'none') {

if (currentSortOrder === undefined) {
this.options.sortOrder = 'asc'
} else if (currentSortOrder === 'asc') {
this.options.sortOrder = 'desc'
} else if (this.options.sortOrder === 'desc') {
this.options.sortOrder = this.options.sortReset ? undefined : 'asc'
}

if (this.options.sortOrder === undefined) {
this.options.sortName = undefined
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ const DEFAULTS = {
sortClass: undefined,
silentSort: true,
sortName: undefined,
sortOrder: 'none',
sortOrder: undefined,
sortReset: false,
sortStable: false,
rememberOrder: false,
serverSort: true,
Expand Down

0 comments on commit caf0440

Please sign in to comment.