Need help for creating a tennis ranking sorting
Need help for creating a tennis ranking sorting
jd-webdesign
Posts: 15Questions: 0Answers: 0
Hi,
I'm working on a tennis club website.
I want to create a table with all the club members and their (french) ranking.
The french tennis ranking works like this (from "bad" to "good") :
NC, 40, 30/5, 30/4, ..., 30/1, 30, 15/5, 15/4,..., 15/1, 15, 5/6, 4/6,..., 1/6, 0, -2/6, -4/6, ...
I start to build the table but the ranking column have wrong sorting, based only on the first number of the ranking.
Is there any way to modify the plugin for my specific case ?
In advance thanks,
JD
I'm working on a tennis club website.
I want to create a table with all the club members and their (french) ranking.
The french tennis ranking works like this (from "bad" to "good") :
NC, 40, 30/5, 30/4, ..., 30/1, 30, 15/5, 15/4,..., 15/1, 15, 5/6, 4/6,..., 1/6, 0, -2/6, -4/6, ...
I start to build the table but the ranking column have wrong sorting, based only on the first number of the ranking.
Is there any way to modify the plugin for my specific case ?
In advance thanks,
JD
This discussion has been closed.
Replies
Docs: http://datatables.net/development/sorting
Examples: http://datatables.net/plug-ins/sorting
Allan
It will be difficult for me because i'm just a beginner in javascript language:((((
Please can you confirm my solution will be found using this method :
http://datatables.net/development/sorting#data_source
And maybe you can jsut give me some clues for starting the "development" of what I need ?
Regards,
JD
Do you have an algorithm for ranking the scores at the moment (regardless of language)? i.e. a bit of code that will take the scores and convert them into something that can be sorted?
Allan
I'm not sure to understood well, but it's not about a tennis score, it's just about a tennis ranking, like number one in the world, number two, ...
So it's like sorting numbers, but the difference is the french tennis ranking is like this :
NC, 40, 30/5, 30/4, ..., 30/1, 30, 15/5, 15/4,..., 15/1, 15, 5/6, 4/6,..., 1/6, 0, -2/6, -4/6, ... (from "bad" to "good" ranking)
Actually the plugin sorts number using the first character of the number and that's the problem for me.
So if you sort the ranking column form "bad to good", 15/5 should appears before 5/6 (5/6 is a better ranking than 15/5) and it's not the case.
I'm not sure if I'm clear!!!!
Please don't hesitate if something is not clear for you.
Regards,
JD
Allan
and the correct ranking is : NC < 40 < 30/5 < 30/4 ...
NC = 10
40 = 9
30/5 = 8
30/4 = 7
etc (or whatever fits). Then you just do a numerical sort.
Allan
Basically make a list of the scores in order and provide a mapping for the values. Think about it - you want to sort numerically, and need to convert from your text values to the numeric equivalent so it can be sorted.
Study this plug-in - http://datatables.net/plug-ins/sorting#weekday - I believe that is basically what you want.
Allan
NC = 24
40 = 23
30/5 = 22
30/4 = 21
30/3 = 20
30/2 = 19
30/1 = 18
30 = 17
15/5 = 16
15/4 = 15
15/3 = 14
15/2 = 13
15/1 = 12
15 = 11
5/6 = 10
4/6 = 9
3/6 = 8
2/6 = 7
1/6 = 6
0 = 5
-2/6 = 4
-4/6 = 3
-15 = 2
-30 = 1
What is the next step ?
And if I find a solution for my problem i will make a donation:)))))
JD
var ranking = new Array();
ranking['-30'] = 1;
ranking['-15'] = 2;
ranking['-4/6'] = 3;
ranking['-2/6'] = 4;
ranking['0'] = 5;
ranking['1/6'] = 6;
ranking['2/6'] = 7;
ranking['3/6'] = 8;
ranking['4/6'] = 9;
ranking['5/6'] = 10;
ranking['15'] = 11;
ranking['15/1'] = 12;
ranking['15/2'] = 13;
ranking['15/3'] = 14;
ranking['15/4'] = 15;
ranking['15/5'] = 16;
ranking['30'] = 17;
ranking['30/1'] = 18;
ranking['30/2'] = 19;
ranking['30/3'] = 20;
ranking['30/4'] = 21;
ranking['30/5'] = 22;
ranking['40'] = 23;
ranking['NC'] = 24;
jQuery.fn.dataTableExt.oSort['ranking-sort-asc'] = function(a,b) {
a = a.toLowerCase();
b = b.toLowerCase();
return ((ranking[a] < ranking[b]) ? -1 : ((ranking[a] > ranking[b]) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['ranking-sort-desc'] = function(a,b) {
a = a.toLowerCase();
b = b.toLowerCase();
return ((ranking[a] < ranking[b]) ? 1 : ((ranking[a] > ranking[b]) ? -1 : 0));
};
Where should I include it ?
JD
Have a look at this example for how to actually use it: http://datatables.net/release-datatables/examples/plug-ins/sorting_sType.html
Allan
var x = (a == "-") ? 0 : a.replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /,/, "." );
regarding to the code I wrote before:(((((((((((((((((((
To get it going I think all you need to do is:
1. Include jQuery
2. Include DataTables
3. Include your plug-in
4. Initialise your DataTable with the sType set for the column that you want to use your sorting plug-in on.
Allan