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

How to Properly Sort a Column with Multiple Lines of Text #1263

Closed
zuve opened this issue Jul 25, 2016 · 3 comments
Closed

How to Properly Sort a Column with Multiple Lines of Text #1263

zuve opened this issue Jul 25, 2016 · 3 comments

Comments

@zuve
Copy link

zuve commented Jul 25, 2016

A table I am working on has one column in it which has multiple lines of text in one table cell. It appears:

value1: example1 value2: example2 value3: example3

When I attempt to sort this column, the table is sorted by its default sort, simply using the first column to sort. Is there a way to assign a custom value to that column that it uses to sort? If possible, it would be great to have a drop down list in the header of the column so that I could select to sort by one of a few custom attributes in the TD's for that column.

@Mottie
Copy link
Owner

Mottie commented Jul 26, 2016

Hi @zuve!

On the home wiki page under sorting are several examples of sorting one column by multiple values. This might be the demo of interest to you; along with the associated Stackoverflow question.

http://jsfiddle.net/abkNM/7862/

@zuve
Copy link
Author

zuve commented Jul 26, 2016

I'm wondering if it would be possible to do the same thing as your demo, but instead use a dropdown menu built in to the column to sort Data1, Data2, or Data3. In addition, would there be some way to set it so that it did not change the sorting(ascending or descending) when changing the dropdown menu?

@Mottie
Copy link
Owner

Mottie commented Jul 26, 2016

That requires even less code (demo):

$(function() {

  var $cell;
  $('table').tablesorter({
    theme: 'blue',
    textSorter: function(a, b) {
      var x = a.split('|'),
        y = b.split('|'),
        i = $cell.val();
      return $.tablesorter.sortNatural($.trim(x[i]), $.trim(y[i]));
    },
    initialized: function() {
      $cell = $('table thead .sort');
    }
  });

});

@zuve zuve closed this as completed Jul 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants