Trouver une ressource (Nouvelle version du moteur, plus rapide & pertinent, essayez le !)
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
TRI DYNAMIQUE DE TABLEAU
Information sur la source
Description
Un script pour vous permettre de trier un tableau dynamiquement sans recharger la page. Permet de trier un tableau à plusieurs colonnes, suffit de créer un tableau pour chaque colonne. Copier-coller et ca roule.
Source
- <html><head>
- <title>Tri dynamique de tableau</title>
- <style>
- .Titre1 { color:BA0000; font-family:'Arial'; font-weight:bold; text-decoration:underline; font-size:15pt; }
- .Titre2 { color:white; background-color:BA0000; font-family:'Arial'; font-weight:bold; font-size:13pt; }
- .Titre3 { color:white; background-color:BA0000; font-family:'Arial'; font-weight:bold; font-size:12pt; }
- .Titre4 { color:black; background-color:E57D7D; font-family:'Arial'; font-weight:bold; font-size:11pt; }
- .Corps { color:black; font-family:'Arial'; font-size:11pt; }
- td { vertical-align:top; }
- a { COLOR:BA0000; TEXT-DECORATION: none }
- a:hover { COLOR:BA0000; TEXT-DECORATION: underline overline }
- </style>
- </head>
-
- <BODY onLoad="triTab(1)">
- <script langage="javascript">
- var tabNum = new Array("#001","#002","#003","#004","#005","#006","#007","#008","#009","#010");
-
- var tabNom = new Array("Dupont","Martin","Toto","Alain","Lulu","Jacques","Laurent","André","Dupond","Marcel");
-
- var tabDesc = new Array("Homme","Femme","Homme","Autre","Femme","Autre","Homme","Femme","Femme","Homme");
-
- function triTab(tabind) {
- var temp;
- var ind01;
- var ind02;
- var tmptab;
-
- switch (tabind) {
- case 1 :
- tmptab = tabNum ;
- break;
- case 2 :
- tmptab = tabNom ;
- break;
- case 3 :
- tmptab = tabDesc ;
- break;
- }
-
- for (ind01 = tmptab.length-1; ind01 >= 0; ind01--) {
- for (ind02 = tmptab.length-1; ind02 >= 0; ind02--) {
- if (tmptab[ind02] < tmptab[ind01]) {
- temp = tabNum[ind02];
- tabNum[ind02] = tabNum[ind01];
- tabNum[ind01] = temp;
- temp = tabNom[ind02];
- tabNom[ind02] = tabNom[ind01];
- tabNom[ind01] = temp;
- temp = tabDesc[ind02];
- tabDesc[ind02] = tabDesc[ind01];
- tabDesc[ind01] = temp;
- }
- }
- }
-
- // construction du tableau
- temp = "<table border='0' width='100%' class='Corps'><tr><td colspan='3' class='Titre4'>Tableau :</td></tr>";
- temp += "<tr><td><a href='#top' onClick='triTab(1)'>par Num</a></td><td><a href='#top' onClick='triTab(2)'>par Nom</a></td><td><a href='#top' onClick='triTab(3)'>par Sexe</a></td></tr>"
- for (ind01 = 0; ind01 < tabNum.length; ind01++) { temp += "<tr><td>" + tabNum[ind01] + "</td><td>" + tabNom[ind01] + "</td><td>" + tabDesc[ind01] + "</td></tr>"; }
- temp += "</table>";
- document.getElementById("tab").innerHTML = temp;
- }
- </script>
- <center>
- <a name="top"></a>
- <div id="tab"> </div>
- </center>
- </body>
- </html>
<html><head>
<title>Tri dynamique de tableau</title>
<style>
.Titre1 { color:BA0000; font-family:'Arial'; font-weight:bold; text-decoration:underline; font-size:15pt; }
.Titre2 { color:white; background-color:BA0000; font-family:'Arial'; font-weight:bold; font-size:13pt; }
.Titre3 { color:white; background-color:BA0000; font-family:'Arial'; font-weight:bold; font-size:12pt; }
.Titre4 { color:black; background-color:E57D7D; font-family:'Arial'; font-weight:bold; font-size:11pt; }
.Corps { color:black; font-family:'Arial'; font-size:11pt; }
td { vertical-align:top; }
a { COLOR:BA0000; TEXT-DECORATION: none }
a:hover { COLOR:BA0000; TEXT-DECORATION: underline overline }
</style>
</head>
<BODY onLoad="triTab(1)">
<script langage="javascript">
var tabNum = new Array("#001","#002","#003","#004","#005","#006","#007","#008","#009","#010");
var tabNom = new Array("Dupont","Martin","Toto","Alain","Lulu","Jacques","Laurent","André","Dupond","Marcel");
var tabDesc = new Array("Homme","Femme","Homme","Autre","Femme","Autre","Homme","Femme","Femme","Homme");
function triTab(tabind) {
var temp;
var ind01;
var ind02;
var tmptab;
switch (tabind) {
case 1 :
tmptab = tabNum ;
break;
case 2 :
tmptab = tabNom ;
break;
case 3 :
tmptab = tabDesc ;
break;
}
for (ind01 = tmptab.length-1; ind01 >= 0; ind01--) {
for (ind02 = tmptab.length-1; ind02 >= 0; ind02--) {
if (tmptab[ind02] < tmptab[ind01]) {
temp = tabNum[ind02];
tabNum[ind02] = tabNum[ind01];
tabNum[ind01] = temp;
temp = tabNom[ind02];
tabNom[ind02] = tabNom[ind01];
tabNom[ind01] = temp;
temp = tabDesc[ind02];
tabDesc[ind02] = tabDesc[ind01];
tabDesc[ind01] = temp;
}
}
}
// construction du tableau
temp = "<table border='0' width='100%' class='Corps'><tr><td colspan='3' class='Titre4'>Tableau :</td></tr>";
temp += "<tr><td><a href='#top' onClick='triTab(1)'>par Num</a></td><td><a href='#top' onClick='triTab(2)'>par Nom</a></td><td><a href='#top' onClick='triTab(3)'>par Sexe</a></td></tr>"
for (ind01 = 0; ind01 < tabNum.length; ind01++) { temp += "<tr><td>" + tabNum[ind01] + "</td><td>" + tabNom[ind01] + "</td><td>" + tabDesc[ind01] + "</td></tr>"; }
temp += "</table>";
document.getElementById("tab").innerHTML = temp;
}
</script>
<center>
<a name="top"></a>
<div id="tab"> </div>
</center>
</body>
</html>
Conclusion
Des questions, des remarques, .... allez-y
Sources de la même categorie
Commentaires
|
CalendriCode
| | | L | M | M | J | V | S | D |
| | | | | 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 |
|
|