The Wayback Machine - https://web.archive.org/web/20201222234657/https://github.com/wenzhixin/bootstrap-table/issues/2864
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort reset on third click #2864

Closed
vveliu opened this issue Jan 13, 2017 · 1 comment
Closed

Sort reset on third click #2864

vveliu opened this issue Jan 13, 2017 · 1 comment
Assignees
Labels

Comments

@vveliu
Copy link

@vveliu vveliu commented Jan 13, 2017

Hello,

I'm using bootstrap-table on my project. I expected that the third click on sorting column resets table sort.

Steps:

  • first click: sort desc
  • second click: sort asc
  • third click: return to default, original data

I need this behavior on my tables.

Currently i have updated bootstrap-table.js and added some extra code to obtain the behavior.

  • In BootstrapTable.prototype.DEFAULTS i add two extra properties:
lastSortOrder : undefined,
dataUnsorted : undefined
  • In BootstrapTable.prototype.initSort:
var currSortOrder = this.options.sortOrder,
      lastSortOrder = this.options.lastSortOrder;

if(lastSortOrder === undefined && this.options.dataUnsorted === undefined){
  this.options.dataUnsorted = this.options.data.slice();
} else if(lastSortOrder === 'asc' && currSortOrder === 'desc'){
   this.options.sortOrder     = 'asc';
   this.options.sortName      = undefined;
   this.options.lastSortOrder = undefined;
   this.options.data          = this.options.dataUnsorted.slice();
   this.data                  = this.options.data;
   this.options.dataUnsorted  = undefined;
     return;
}

if(!(lastSortOrder === undefined && currSortOrder === 'asc'))
   this.options.lastSortOrder = currSortOrder;
  • In BootstrapTable.prototype.onSort:
if (this.options.sortName === $this.data('field')) { 
   this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc';
} else {
   this.options.sortName = $this.data('field');

   if(this.options.lastSortOrder === undefined)
      #this.options.sortOrder = 'desc';
  else
      this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
}
@Ericzhiluo
Copy link

@Ericzhiluo Ericzhiluo commented Jan 31, 2018

i have the same need too. Please add this feature as it will make the sorting function more natural

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants
You can’t perform that action at this time.