Sort integer ascending and put empty cells to the bottom
Sort integer ascending and put empty cells to the bottom
Hello everyone!
I have some problems with ascending sorting of a column. Here is how my table looks like.
[code]
First events Second Event Third event
Team Position Points Position Points Position Points
Team A 1 100 2 90 1 100
Team B 1 100 3 80
Team C 2 90 2 90
[/code]
so it's an overview of teams who competed in three events. the table is sortable for position of each event. Some teams did not compete in all events. When i now want to sort the second event, Team C is in top, which is obivously wrong.
Now I'm trying to find a solution, how i can put empty cells on the bottom of the sorted column. I found a few older threads (yes i searched before starting a new topic) about the same issue, but those solutions don't really seem to work.
I use Wordpress and the Tablepress plugin, which is based on Datatables.
This was the best thread i found about my problem: http://datatables.net/forums/discussion/4025/sorting-to-ignore-empty-cells/p1
Thank you in advance!
I have some problems with ascending sorting of a column. Here is how my table looks like.
[code]
First events Second Event Third event
Team Position Points Position Points Position Points
Team A 1 100 2 90 1 100
Team B 1 100 3 80
Team C 2 90 2 90
[/code]
so it's an overview of teams who competed in three events. the table is sortable for position of each event. Some teams did not compete in all events. When i now want to sort the second event, Team C is in top, which is obivously wrong.
Now I'm trying to find a solution, how i can put empty cells on the bottom of the sorted column. I found a few older threads (yes i searched before starting a new topic) about the same issue, but those solutions don't really seem to work.
I use Wordpress and the Tablepress plugin, which is based on Datatables.
This was the best thread i found about my problem: http://datatables.net/forums/discussion/4025/sorting-to-ignore-empty-cells/p1
Thank you in advance!
This discussion has been closed.
Replies
Sounds like you want multi-coloum sorting by default, which can be done with aDataSort - provide an array of the columns you want sorting to occur on. The default is just one column, but you can add more.
Allan
There are lots of sorting plug-ins in the plug-ins section of the site as well.
Allan
is there someone who could test this code and tell me what i need to change to make it work with my table?
[code]
jQuery.fn.dataTableExt.oSort['mystring-asc'] = function(x,y) {
var retVal;
x = $.trim(x);
y = $.trim(y);
if (x==y) retVal= 0;
else if (x == "" || x == " ") retVal= 1;
else if (y == "" || y == " ") retVal= -1;
else if (x > y) retVal= 1;
else retVal = -1; // <- this was missing in version 1
return retVal;
}
jQuery.fn.dataTableExt.oSort['mystring-desc'] = function(y,x) {
var retVal;
x = $.trim(x);
y = $.trim(y);
if (x==y) retVal= 0;
else if (x == "" || x == " ") retVal= -1;
else if (y == "" || y == " ") retVal= 1;
else if (x > y) retVal= 1;
else retVal = -1; // <- this was missing in version 1
return retVal;
}
[/code]