Bonjour,

J'essaye de faire une petite fonction me permettant de classer un tableau selon le clique sur le titre.

Voici un extrait de code :
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
 
 
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
 
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<script type="text/javascript">
var jeu= new Array();
jeu[0]= new Array(1,'arnold','homme','rouge',17,'soissons','cheval');
jeu[1]= new Array(4,'willy','homme','bleu',27,'belleu','chien');
jeu[2]= new Array(3,'amélie','femme','rouge',18,'marseille','chat');
jeu[3]= new Array(2,'nicolas','homme','noir',24,'conlie','dauphin');
jeu[4]= new Array(5,'gwen','femme','jaune',40,'gournay sur aronde','cochon');
jeu[5]= new Array(6,'pomme','femme','orange',17,'soissons','rouge gorge');
 
var tousTotal= jeu.length;
 
function afficheTableau(maTable) {
	var ancienne=document.getElementById('table_jeu');
	var monParent=ancienne.parentNode;
	monParent.removeChild(ancienne);
	var nouveau =document.createElement("table");
	nouveau.id='table_jeu';
	var newLigne = document.createElement("tr");
	var titre = new Array('Classement','Prenom','Genre','Couleur','Age','Ville','Animal');
	for(i=0;i<titre.length;i++){
		var newCellule = document.createElement("th");
		var newA = document.createElement('a');
		newA.href = 'javaScript:classement('+i+');';
		var text=document.createTextNode(titre[i]);
		newA.appendChild(text);
		newCellule.appendChild(newA);
		newLigne.appendChild(newCellule);
	}
	nouveau.appendChild(newLigne);
	// Création des lignes d'articles
	for(i=0;i<maTable.length;i++){
		var laLigne=maTable[i];
		var newLigne = document.createElement("tr");
		newLigne.name='joueur'+laLigne[0];
		for(j=0;j<laLigne.length;j++){
			var newCellule = document.createElement("td");
			var text=document.createTextNode(laLigne[j]);
			newCellule.appendChild(text);
			newLigne.appendChild(newCellule);
		}
		nouveau.appendChild(newLigne);
	}
	// Insertion du tableau dans le document
	monParent.appendChild(nouveau);
}
 
 
function classement(choix){
	var tmpTab = new Array();
	var newTable = new Array();
	var numeroLigne = new Array();
	var temp;
	var indice1;
	var indice2;
	for(i=0;i<jeu.length;i++){
		ligne = jeu[i];
		tmpTab[i] = ligne[choix];
		numeroLigne[i] = i ;
	}
	for (indice1 = 0; indice1 < tmpTab.length ; indice1++) {
		for (indice2 = 0; indice2 < tmpTab.length; indice2++) {
			if (tmpTab[indice2] > tmpTab[indice1]) {
				temp = numeroLigne[indice2];
				numeroLigne[indice2] = numeroLigne[indice1];
			        numeroLigne[indice1] = temp;
			}
		}
	}
	for(i=0;i<numeroLigne.length;i++){
		newTable[i] = jeu[numeroLigne[i]];
	}
	afficheTableau(newTable);
}
</script>
<title>Test Script</title>
</head>
<body id="index" onload ='afficheTableau(jeu);' >
<div id="titre"><h1>Test Script</h1></div>
<div id='presentation'>
<table id='table_jeu'>
</table>
</div>
</body>
</html>
Le problème est que ce code classe n'importe comment.

Et, je n'arrive pas à trouver ou est mon erreur.