Reputation: 1362
I have seven columns and I would like to have them sort correctly,
The first column has numbers but it doesn't order them the way I would like them to be ordered:
Example:
5016
502
5020
5023
where I would like it to sort like this:
Example:
502
5016
5020
5023
Now the 2nd column has a combination of numbers and letters example is like above but has a letter in the front before each number I would like to sort that by numbers, then by letters
Example:
441
B441
821
822
823
C823
or even like this would be OK
Example:
441
821
822
823
B441
C823
and finally, the 3rd column is more complex it has a image before the words example is: Billy Jones Anna Walters Bob Smith Tom Henderson
All I want it to order by (names) letters...
Example:
<img src="img_tr122.png"> Anna Walters
<img src="img_tr122.png"> Billy Jones
<img src="img_tr122.png"> Bob Smith
<img src="img_tr122.png"> Tom Henderson
here is what I have in the JavaScript so far but I don't know how to get everything to work..
<script type="text/javascript">
$(document).ready(function() {
$.tablesorter.defaults.widgets = ['zebra'];
$("table").tablesorter({
// pass the headers argument and assing a object
headers: {
// assign the third column (we start counting zero)
2: {
// disable sort because I don't know how to sort it correctly.
sorter: false
},
6: {
// disable sort for this (last) column because it is a menu only.
sorter: false
}
}
});
});
</script>
PLEASE HELP....
THANKS!!!!
Upvotes: 0
Views: 1929
Reputation: 13381
You can use http://tablesorter.openwerk.de/ which has the functionality you need and it has locale support, UI themes support, support for german date format and decimal points.
Upvotes: 0
Reputation: 86413
The original tablesorter (v2.0.5) doesn't do alphanumeric sorting. But you can use my fork of tablesorter to sort your data using this code:
$('table').tablesorter({
// Add a theme
theme : 'blue',
// extract text from the table
textExtraction: {
2: function(node) {
// move swap first and last name
return $.trim($(node).text() || '').replace(/(\w+)\s(\w+)/g,'$2 $1');
}
},
// include zebra and any other widgets:
widgets: ['zebra', 'columns']
});
I wasn't sure how you wanted to sort the last column. The textExtraction
option contains code to sort the last column by last name first. If you want to sort by the first name, then just remove the entire option.
Here is a demo of that code in action.
Upvotes: 2