IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

modifier un tableau avec javascript


Sujet :

JavaScript

  1. #21
    Expert confirmé
    Avatar de javatwister
    Homme Profil pro
    danseur
    Inscrit en
    Août 2003
    Messages
    3 681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : danseur

    Informations forums :
    Inscription : Août 2003
    Messages : 3 681
    Points : 5 221
    Points
    5 221
    Par défaut
    teste ça, si tu veux:

    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
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
     
    <title>...</title> 
     
    <style type="text/css"> 
    #tab1 td { 
    text-align:center;
    width:40px;
    height:30px;
    background-color:#ff0000; 
    font-weight:bold 
    } 
     
    </style> 
     
     
    </head> 
     
    <body> 
     
    <p>
    <strong>En cliquant sur une cellule quelconque, on efface la colonne.</strong>
    <br />
    Effectivement, le travail est long, que ce soit pour générer la page, d'ailleurs, 
    ou pour gérer toutes les cellules;<br />
    (là, je n'ai que 1000 lignes)
    </p>
     
    <div id="cadre"></div> 
     
    <script type="text/javascript"> 
     
    function efface(col){
    var tt=document.getElementById("tab1").getElementsByTagName("td");
     
    	for(i=0;i<tt.length;i++){
    		if(tt[i].getAttribute(col)){ 
    		     tt[i].style.display='none' 
    		}
    	}
    }
     
     
    var tab=["zero","un","deux","trois","quatre","cinq","six","sept","huit","neuf"];
    var t=document.createElement("table"); 
    t.setAttribute("id","tab1"); 
     
    var tb=document.createElement("tbody"); 
    t.appendChild(tb); 
     
    for(i=0;i<1000;i++){ 
    	l=document.createElement("tr"); 
    	for(j=0;j<10;j++){ 
    		c=document.createElement("td");
    		c.attr=tab[j];
    		c.appendChild(document.createTextNode(tab[j])); 
    		c.setAttribute(tab[j],tab[j]);
    		c.onclick=function(){
    			efface(this.attr)
    		}
    	l.appendChild(c); 
    	}; 
     
    tb.appendChild(l); 
    }; 
     
    document.getElementById("cadre").appendChild(t); 
     
    </script> 
     
     
    </body> 
     
    </html>

    chez moi, Ffx met une demi-seconde à effacer la colonne et IE 8 secondes!

  2. #22
    Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    87
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Service public

    Informations forums :
    Inscription : Juillet 2005
    Messages : 87
    Points : 69
    Points
    69
    Par défaut
    en fait toi tu créé ton tableau en js et moi je le créé en htlm et dupliquer avec coldfusion en y incluant les données venant de la database.

    donc je ne sais pas si je sais utiliser le setAttribute

  3. #23
    Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    87
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Service public

    Informations forums :
    Inscription : Juillet 2005
    Messages : 87
    Points : 69
    Points
    69
    Par défaut
    je te donne aussi du code une fois le tableau généré :

    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
     
    <td align="right" id="ordDRPFL.0111044851"><span id="1.ordDRPFL.0111044851"></span></td>
    		<td align="right" id="ordDRPFL.0111044852"><span id="2.ordDRPFL.0111044852"></span></td>
    		<td align="right" id="ordDRPFL.0111044853"><span id="3.ordDRPFL.0111044853"></span></td>
    		<td align="right" id="ordDRPFL.0111044854"><span id="4.ordDRPFL.0111044854"></span></td>
    		<td align="right" id="antDRPFL.0111044855"><span id="5.antDRPFL.0111044855"></span></td>
    		<td align="right" id="antDRPFL.0111044856"><span id="6.antDRPFL.0111044856"></span></td>
    		<td align="right" id="antDRPFL.0111044857"><span id="7.antDRPFL.0111044857"></span></td>
    		<td align="right" id="antDRPFL.0111044858"><span id="8.antDRPFL.0111044858"></span></td>
    		<td align="right" id="chaDRPFL.0111044859"><span id="9.chaDRPFL.0111044859"></span></td>
    		<td align="right" id="chaDRPFL.01110448510"><span id="10.chaDRPFL.01110448510"></span></td>
    		<td align="right" id="chaDRPFL.01110448511"><span id="11.chaDRPFL.01110448511"></span></td>
    		<td align="right" id="chaDRPFL.01110448512"><span id="12.chaDRPFL.01110448512"></span></td>
    		<td align="right" id="kapDRPFL.01110448517"><span id="17.kapDRPFL.01110448517"></span></td>
    		<td align="right" id="kapDRPFL.01110448518"><span id="18.kapDRPFL.01110448518"></span></td>
    		<td align="right" id="kapDRPFL.01110448519"><span id="19.kapDRPFL.01110448519"></span></td>
    		<td align="right" id="kapDRPFL.01110448520"><span id="20.kapDRPFL.01110448520"></span></td>
    		<td align="right" id="nserDRPFL.01110448521"><span id="21.nserDRPFL.01110448521"></span></td>
    		<td align="right" id="nserDRPFL.01110448522"><span id="22.nserDRPFL.01110448522"></span></td>
    		<td align="right" id="nserDRPFL.01110448523"><span id="23.nserDRPFL.01110448523"></span></td>
    		<td align="right" id="nserDRPFL.01110448524"><span id="24.nserDRPFL.01110448524"></span></td>
    		<td align="right" id="sserDRPFL.01110448525"><span id="25.sserDRPFL.01110448525"></span></td>
    		<td align="right" id="sserDRPFL.01110448526"><span id="26.sserDRPFL.01110448526"></span></td>
    		<td align="right" id="sserDRPFL.01110448527"><span id="27.sserDRPFL.01110448527"></span></td>
    		<td align="right" id="sserDRPFL.01110448528"><span id="28.sserDRPFL.01110448528"></span></td>
    		<td align="right" id="dserDRPFL.01110448529"><span id="29.dserDRPFL.01110448529"></span></td>
    		<td align="right" id="dserDRPFL.01110448530"><span id="30.dserDRPFL.01110448530"></span></td>
    		<td align="right" id="dserDRPFL.01110448531"><span id="31.dserDRPFL.01110448531"></span></td>
    		<td align="right" id="dserDRPFL.01110448532"><span id="32.dserDRPFL.01110448532"></span></td>
    		<td align="right" id="nspeDRPFL.01110448533"><span id="33.nspeDRPFL.01110448533"></span></td>
    		<td align="right" id="nspeDRPFL.01110448534"><span id="34.nspeDRPFL.01110448534"></span></td>
    		<td align="right" id="nspeDRPFL.01110448535"><span id="35.nspeDRPFL.01110448535"></span></td>
    		<td align="right" id="nspeDRPFL.01110448536"><span id="36.nspeDRPFL.01110448536"></span></td>
    		<td align="right" id="sspeDRPFL.01110448537"><span id="37.sspeDRPFL.01110448537"></span></td>
    		<td align="right" id="sspeDRPFL.01110448538"><span id="38.sspeDRPFL.01110448538"></span></td>
    		<td align="right" id="sspeDRPFL.01110448539"><span id="39.sspeDRPFL.01110448539"></span></td>
    		<td align="right" id="sspeDRPFL.01110448540"><span id="40.sspeDRPFL.01110448540"></span></td>
    		<td align="right" id="dspeDRPFL.01110448541"><span id="41.dspeDRPFL.01110448541"></span></td>
    		<td align="right" id="dspeDRPFL.01110448542"><span id="42.dspeDRPFL.01110448542"></span></td>
    		<td align="right" id="dspeDRPFL.01110448543"><span id="43.dspeDRPFL.01110448543"></span></td>
    		<td align="right" id="dspeDRPFL.01110448544"><span id="44.dspeDRPFL.01110448544"></span></td>
    maintenant tu as le vrais nom des td et tu comprendras mieux pourquoi j'ai utilisé une regexp

    ne t'occupe pas du span il est juste la pour recevoir des données de d'autres td par le biais de javascript

  4. #24
    Expert confirmé
    Avatar de javatwister
    Homme Profil pro
    danseur
    Inscrit en
    Août 2003
    Messages
    3 681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : danseur

    Informations forums :
    Inscription : Août 2003
    Messages : 3 681
    Points : 5 221
    Points
    5 221
    Par défaut
    à mon avis, pas de problème majeur pour ajouter un attribut html dans chaque ligne en même temps que l'id;
    pour le coup, l'attribut n'est évidemment pas politiquement correct pour le w3c mais ça peut valoir le coup;

    peux-tu donc arriver à un truc du genre:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td align="right" ordDRPFL="ordDRPFL" id="ordDRPFL.0111044852"><span id="2.ordDRPFL.0111044852"></span></td>
    ?

  5. #25
    Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    87
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Service public

    Informations forums :
    Inscription : Juillet 2005
    Messages : 87
    Points : 69
    Points
    69
    Par défaut
    je vais essayer je te tiens au courant

    merci de ton aide en tous cas

  6. #26
    Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    87
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Service public

    Informations forums :
    Inscription : Juillet 2005
    Messages : 87
    Points : 69
    Points
    69
    Par défaut
    j'ai ajouté les attributs j'ai modifié le js mais tjs pas d'évolution (tjs aussi lent).

    le probleme c'est qu'il prend en compte tous les td du tableau n'y aurait-il pas moyen de filtrer les td avant ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    function hide_col(a,c,d,e){
    alert(e);
    var tds=document.getElementById(c).getElementsByTagName(d);
    alert(tds.length);
    for(var i=0;i<tds.length;i++){ 
          if(tds[i].getAttribute(e)){ 
               tds[i].style.display="none";
          } 
       } 
    }

  7. #27
    Expert confirmé
    Avatar de javatwister
    Homme Profil pro
    danseur
    Inscrit en
    Août 2003
    Messages
    3 681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : danseur

    Informations forums :
    Inscription : Août 2003
    Messages : 3 681
    Points : 5 221
    Points
    5 221
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
     
    function hide_col(a,c,d,e){ 
    alert(e); 
    var tds=document.getElementById(c).getElementsByTagName(d); 
    alert(tds.length); 
    for(var i=0;i<tds.length;i++){ 
          if(tds[i].getAttribute(e)){ 
               tds[i].style.display="none"; 
          } 
       } 
    }
    c'est exactement ce que je fais et aucune sélection n'est possible avant le scan du tableau de <td>;

    autre solution, crée un attribut name pour chaque cellule (même technique) en changeant sa valeur selon la colonne;
    appelle la colonne par getElementsByTagName() et tu auras tes cellules beaucoup plus vite;

    2 bémols:
    "name" n'est pas valide w3c et IE intègre parfois mal cet attribut quand il est créé dynamiquement;

  8. #28
    Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    87
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Service public

    Informations forums :
    Inscription : Juillet 2005
    Messages : 87
    Points : 69
    Points
    69
    Par défaut
    Voila j'ai trouvé une soluce en mixant les idées de plusieurs.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    function hide_col(a,c,d,e){
    var t=document.getElementById(c);
    for ( var l=0;l<t.rows.length;l++ )
    {
     for ( var i=0;i<t.rows[l].cells.length;i++ )
     {
      if ( t.rows[l].cells[i].ord == e)
      {
       document.getElementById(t.rows[l].cells[i].id).style.display='none';
      }
     }
    }
    }
    je sais aller chercher un attribut, le tester et le tout sur la ligne et non sur le td.

    enfin soit le principale c'est que ca fonctionne.

    un grand Merci a tous ceux qui mon aidé dans cette recherche.

    Lemmings

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. [DOM] Modifier un onclick avec Javascript
    Par Sebastien14 dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 19/01/2009, 11h01
  2. Modifier un tableau avec innerHTML sous IE
    Par Gédéon dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 06/12/2006, 12h32
  3. Réponses: 11
    Dernier message: 14/10/2006, 21h26
  4. [Excel]Ouvrir un tableau avec une liste modifiable
    Par mulot03 dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 04/05/2006, 09h52
  5. Inclure une page dans dans une tableau avec javascript
    Par pierrot10 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 26/09/2005, 12h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo