Need help for creating a tennis ranking sorting

Need help for creating a tennis ranking sorting

jd-webdesignjd-webdesign Posts: 15Questions: 0Answers: 0
edited May 2012 in Feature requests
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

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Absolutely - you can create a sorting plug-in that will sort your data in the exact way you wish:

    Docs: http://datatables.net/development/sorting
    Examples: http://datatables.net/plug-ins/sorting

    Allan
  • jd-webdesignjd-webdesign Posts: 15Questions: 0Answers: 0
    Hi, thanks a lot for your answer:))))

    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
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    I'd imagine actually that you want to use the standard method of sorting: http://datatables.net/development/sorting#type_based .

    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
  • jd-webdesignjd-webdesign Posts: 15Questions: 0Answers: 0
    Hi,

    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
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Do you have an algorithm for that at the moment in some other language? i.e how are you going to tell the computer that 40 > 30/5?

    Allan
  • jd-webdesignjd-webdesign Posts: 15Questions: 0Answers: 0
    edited May 2012
    thanks again for your answer, no I don't have an algorithm:(((((

    and the correct ranking is : NC < 40 < 30/5 < 30/4 ...
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    So - priority one - create an algorithm :-). Can you just use string matching for example?

    NC = 10
    40 = 9
    30/5 = 8
    30/4 = 7

    etc (or whatever fits). Then you just do a numerical sort.

    Allan
  • jd-webdesignjd-webdesign Posts: 15Questions: 0Answers: 0
    edited May 2012
    I can create a file like your example no problem but which type of file (.txt, ...) ?
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    I'd rather you wrote the code here, unless you want to purchase some priority support for DataTables :-)

    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
  • jd-webdesignjd-webdesign Posts: 15Questions: 0Answers: 0
    ok so I wrote the "code" like this :

    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
  • jd-webdesignjd-webdesign Posts: 15Questions: 0Answers: 0
    ok i will try with the weekdays example:)))))
  • jd-webdesignjd-webdesign Posts: 15Questions: 0Answers: 0
    ok i create this code :

    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
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Looks good!

    Have a look at this example for how to actually use it: http://datatables.net/release-datatables/examples/plug-ins/sorting_sType.html

    Allan
  • jd-webdesignjd-webdesign Posts: 15Questions: 0Answers: 0
    edited May 2012
    sorry but I don't know what I have to change in this lines :

    var x = (a == "-") ? 0 : a.replace( /,/, "." );
    var y = (b == "-") ? 0 : b.replace( /,/, "." );


    regarding to the code I wrote before:(((((((((((((((((((
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    I don't think you need to use those two lines at all do you? Your plug-in looks fine to me as it is!

    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
This discussion has been closed.