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

Sorting direction as the third argument in onSort #1193

Closed
oskarkrawczyk opened this issue Apr 9, 2013 · 0 comments · Fixed by #1332
Closed

Sorting direction as the third argument in onSort #1193

oskarkrawczyk opened this issue Apr 9, 2013 · 0 comments · Fixed by #1332

Comments

@oskarkrawczyk
Copy link
Contributor

onSort should pass the sorting direction as the third argument.

Original code:

sort: function(index, reverse, pre){
  if (!this.head) return;

  if (!pre){
    this.clearSort();
    this.setSortedState(index, reverse);
    this.setHeadSort(true);
  }

  var parser = this.getParser();
  if (!parser) return;

  var rel;
  if (!Browser.ie){
    rel = this.body.getParent();
    this.body.dispose();
  }

  var data = this.parseData(parser).sort(function(a, b){
    if (a.value === b.value) return 0;
    return a.value > b.value ? 1 : -1;
  });

  if (this.sorted.reverse == (parser == HtmlTable.Parsers['input-checked'])) data.reverse(true);
  this.setRowSort(data, pre);

  if (rel) rel.grab(this.body);
  this.fireEvent('stateChanged');
  return this.fireEvent('sort', [this.body, this.sorted.index]);
}

New:

sort: function(index, reverse, pre){
  if (!this.head) return;

  if (!pre){
    this.clearSort();
    this.setSortedState(index, reverse);
    this.setHeadSort(true);
  }

  var parser = this.getParser();
  if (!parser) return;

  var rel;
  if (!Browser.ie){
    rel = this.body.getParent();
    this.body.dispose();
  }

  var data = this.parseData(parser).sort(function(a, b){
    if (a.value === b.value) return 0;
    return a.value > b.value ? 1 : -1;
  });

  var reversed = this.sorted.reverse == (parser == HtmlTable.Parsers['input-checked']);

  if (reversed) data.reverse(true);
  this.setRowSort(data, pre);

  if (rel) rel.grab(this.body);
  this.fireEvent('stateChanged');

  return this.fireEvent('sort', [this.body, this.sorted.index, reversed]);
}

This change is needed so the correct order can be applied upon reloading.

I see there are 43 open pull requests, so I'm not going to bother with queuing yet another one... Unless you like the change and will apply it straight away, then I'll create a pull request :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant