bonjour,

le tri de ma table par un javascript ne me laisse pas présenter celle-ci comme je le veux .
Par défaut, sur les 5 colonnes dont 1 présente les dates, c'est celle des dates qui est triée par défaut, et de façon croissante . (plus petit vers plus grand)
J'ai besoin de la présenter par défaut en tri décroissant .
Que faut-il modifier : le script, et si oui , comment procéder, sachant que je ne sais que m'en servir ... ou / et faut-il modifier le code dans le <body>) ?

voici le code dans le <head>, qui pointe vers les fichiers script :

Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
<!-- SCRIPT Tri table TableClips  -->
<script type="text/javascript" src="tablesort.js">
</script>
<script type="text/javascript" src="customsort.js">
</script>

voici le code dans le <body> où la colonne "Date" reçoit sa fonction "sortable-sortEnglishDateTime" :

Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
<thead class="thead">
    <tr>
        <th  width="220" class="sortable-text"scope="col">ARTISTE / GROUPE</th>
        <th  width="285" class="sortable-text" scope="col">TITRE</th>
        <th  width="60" class="sortable-text" scope="col">Media</th>
        <th  width="88" class="sortable-text" scope="col">Posteur</th>
        <th  width="137" class="sortable-sortEnglishDateTime" scope="col">Date</th>
      </tr>
    </thead>
 
<?php include('TbodyTableClips.php'); ?>

Voici le code de "customsort.js" qui porte la fonction sortEnglishDateTime :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var sortEnglishDateTime = fdTableSort.sortNumeric;
 
function sortEnglishDateTimePrepareData(tdNode, innerText) {
        // You can localise the function here
        var months = ['january','february','march','april','may','june','july','august','september','october','november','december','jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'];
 
        // Lowercase the text
        var aa = innerText.toLowerCase();       
 
        // Replace the longhand and shorthand months with an integer equivalent
        for(var i = 0; i < months.length; i++) {               
                aa = aa.replace(new RegExp(months[i] + '([\\s|,]{1})'), (i+13)%12 + " ");
        };
 
        // Replace multiple spaces and anything that is not valid in the parsing of the date, then trim
        aa = aa.replace(/\s+/g, " ").replace(/([^\d\s\/-:.])/g, "").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
 
        // REMOVED: No timestamp at the end, then return -1
        //if(aa.search(/(\d){2} [decu]\d){2}( [decu]\d){2})?$/) == -1) { return -1; };
 
        // No timestamp at the end, then create a false one       
        if(aa.search(/(\d){2} [decu]\d){2}( [decu]\d){2})?$/) == -1) { aa += " 00:00:00"; };
 
 
        // Grab the timestamp
        var timestamp = aa.match(/(\d){2} [decu]\d){2}( [decu]\d){2})?$/)[0].replace(/:/g, "");
 
        // Make the timestamp 6 characters by default
        if(timestamp.length == 4) { timestamp += "00"; };
 
        // Remove it from the string to assist the date parser, then trim
        aa = aa.replace(/(\d){2} [decu]\d){2}( [decu]\d){2})?$/, "").replace(/\s\s*$/, '');
 
        // If you want the parser to favour the parsing of European dd/mm/yyyy dates then leave this set to "true"
        // If you want the parser to favour the parsing of American mm/dd/yyyy dates then set to "false"
        var favourDMY = true;
 
        // If you have a regular expression you wish to add, add the Object to the end of the array
        var dateTest = [
                       { regExp:/^(0?[1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])([- \/.])((\d\d)?\d\d)$/, d:3, m:1, y:5 },  // mdy
                       { regExp:/^(0?[1-9]|[12][0-9]|3[01])([- \/.])(0?[1-9]|1[012])([- \/.])((\d\d)?\d\d)$/, d:1, m:3, y:5 },  // dmy
                       { regExp:/^(\d\d\d\d)([- \/.])(0?[1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])$/, d:5, m:3, y:1 }      // ymd
                       ];
 
        var start,y,m,d;
        var cnt = 0;
        var numFormats = dateTest.length;
        while(cnt < numFormats) {
               start = (cnt + (favourDMY ? numFormats + 1 : numFormats)) % numFormats;
               if(aa.match(dateTest[start].regExp)) {
                       res = aa.match(dateTest[start].regExp);
                       y = res[dateTest[start].y];
                       m = res[dateTest[start].m];
                       d = res[dateTest[start].d];
                       if(m.length == 1) m = "0" + String(m);
                       if(d.length == 1) d = "0" + String(d);
                       if(y.length != 4) y = (parseInt(y) < 50) ? "20" + String(y) : "19" + String(y);
 
                       return y+String(m)+d+String(timestamp);
               };
               cnt++;
        };
        return -1;
};
Merci d'avance pour votre aide ....