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 :

Redimensionnement dynamique d'une colonne


Sujet :

JavaScript

  1. #1
    Membre averti
    Inscrit en
    Octobre 2010
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 26
    Par défaut Redimensionnement dynamique d'une colonne
    Bonjour tout le monde,

    J'aimerais savoir s'il existe une solution "simple" qui me permette de redimensionner une colonne d'un tableau qui est rempli dynamiquement à l'aide d'un formulaire.
    Il s'agit de la colonne DETAIL PLN

    Voici le code associé (je sais qu'il n'est pas optimisé mais je ne connais pas vraiment le langage, juste l'algorithmie) :

    Code html : 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
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
     
    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8">
        <title>Le titre du document</title>
        <style>
                    {
                            border: 0;
                            margin: 0;
                            padding: 0;
                    }
     
                    table 
                    {
                            text-align: left;
                            border-spacing: 0px;
                            border: 1px solid #aeb3b6;
                            border-collapse: collapse;
                            width: 80%;
                            table-layout: fixed;
                    }
     
     
                    table a, table, tbody, tfoot, tr, th, td 
                    {
                       font-family: Arial, Helvetica, sans-serif;
                            line-height: 2.0em;
                            font-size: 13px;
                            color: #55595c;
                    }
     
                    tbody td{
                            line-height: 2.5em;
                    }
     
                    table caption
                    {
                            padding: .4em 0 ;
                            font-size: 240%;
                            font-style: normal;
                            color: #FB7E00;
                    }
     
                    table a
                    {
                            display: block;
                            text-decoration: none;
                            color: #FF8E53;
                            padding-right: 1.5em;
     
                    }
     
                    table a:hover, table a:focus
                    {
                    text-decoration: underline;
                    }
     
                    table th a
                    {
                            color: #FF8E53;
                            text-align: right;
                    }
                    table .odd th a,table .odd td a,table .odd td{
                            color: #666;
                            padding-right: 1.0 em;
                    }
     
                    table th a:hover, table th a:focus, tbody tr:hover th
                    {   
                       background-color: #FFCC99;
                            color: #fff !important;
                    }
                    table .odd th,table .odd td{
                            background-color: #DDDDDD;
                    }
     
                    thead th
                    {
                            background-color: #8f8f8f;
                            text-transform: uppercase;
                            font-weight: normal;
                            letter-spacing: 1px;
                            color: #fff;
     
                    }
     
                    tfoot{
                            border-top: 1px solid #fff;
                    }
     
                    tfoot th,tfoot td{
                            color: #fff;
                    }
     
                    tbody th
                    {
                       padding-right: 1.0em;
                            color: #25c1e2;
                            font-style: normal;
                            background-color: #fff;
                            border-bottom: 1px dotted #aeb3b6;
                    }
     
                    td
                    {
                       color: #FF8E1C;
                            border-bottom: 1px dotted #aeb3b6;
                            padding-right: 0.5em;
                            max-width: 35%;
     
                    }
     
                    tbody tr.odd
                    {
                            border-bottom: 1px dotted #aeb3b6;
                    }
     
                    tbody tr:hover td
                    {
                      background-color: #FFCC99;
                    }
     
                    tbody tr:hover td,tbody tr:hover th, tbody tr:hover a
                    {
                            color: #fff !important;
                    }
                    .tri { FONT:bold 12 Arial; CURSOR:pointer }
     
                    fieldset {
                      margin-bottom: 15px;
                      padding: 10px;
                      width: 50%;
                    }
     
                    legend {
                      padding: 0px 3px;
                      font-weight: bold;
                      font-variant: small-caps;
                    }
     
                    label {
                      width: 110px;
                      display: inline-block;
                      vertical-align: top;
                      margin: 6px;
                    }
            </style>
      </head>
      <body>
    	<form method="post" action="" id="myForm">
    		<fieldset>
    			<legend>Informations relatives au PNL</legend>
    			<label for="indicatif">Indicatif</label>
    			<input type="text" name="indicatif" id="indicatif" />
    			<label for="ETD">ETD</label>
    			<input type="text" name="ETD" id="ETD" /><br />
    			<label for="ADEP">ADEP</label>
    			<input type="text" name="ADEP" id="ADEP" />
    			<label for="ADES">ADES</label>
    			<input type="text" name="ADES" id="ADES" /><br />
    			<label for="Detail_PLN">Détail PNL</label>
    			<textarea name="Detail_PLN" id="Detail_PLN" rows="5" cols="50"></textarea><br />
    			<label for="IFF_SIF">IFF/SIF</label>
    			<input type="text" name="IFF_SIF" id="IFF_SIF" />
    			<label for="Nb_AC">Nb A/C</label>
    			<input type="text" name="Nb_AC" id="Nb_AC" /><br />
    			<label for="num"></label>
    			<input type="text" name="num" id="num" /><br />
    			<input type="button" onclick="ajouterLigne();" value="Ajouter la ligne" id="ajout"/> <input type="reset" />
    			<input type="button" onclick="modifierSuite();" value="Modifier la ligne" id="modifier2"/>
    		</fieldset>
    	</form>
    	<script>
                    document.getElementById("modifier2").disabled=true;
            </script>
        <table id="tableau">
        	<thead>
        		<tr class=title>
    				<th>Indicatif</th>
    				<th>ETD<span class="tri" onclick=TableOrder(event,1)></span><span class="tri" onclick=TableOrder(event,0)></span></th>
    				<th>ADEP</th>
    				<th>ADES</th>
    				<th>Detail PLN</th>
    				<th>IFF/SIF</th>
    				<th>Nb A/C</th>
    				<th></th>
    				<th>Modification</th>
    			</tr>
        	</thead>
        	<tbody>
    <!--				<tr><td>MARCOU41</td><td>0830</td><td>BC</td><td>T43</td><td>RBT</td><td>6551</td><td>2</td><td>02BC</td><td><input type="button" onclick="modifier1(this);" value="Modifier"/></td></tr>
    				<tr><td>RAYAK81</td><td>0700</td><td>BM</td><td>SIMONE</td><td>RVT</td><td>6561</td><td>4</td><td>08BM</td><td><input type="button" onclick="modifier1(this);" value="Modifier"/></td></tr>
    				<tr><td>RIVAGE23</td><td>1730</td><td>BC</td><td>BG</td><td>R49H1</td><td></td><td>3</td><td>06BC</td><td><input type="button" onclick="modifier1(this);" value="Modifier"/></td></tr>
    				<tr><td>MARCOU41</td><td>0830</td><td>BC</td><td>T43</td><td>RBT</td><td>6551</td><td>2</td><td>02BC</td><td><input type="button" onclick="modifier1(this);" value="Modifier"/></td></tr>
    				<tr><td>RAYAK81</td><td>0700</td><td>BM</td><td>SIMONE</td><td>RVT</td><td>6561</td><td>4</td><td>08BM</td><td><input type="button" onclick="modifier1(this);" value="Modifier"/></td></tr>
    				<tr><td>RIVAGE23</td><td>1730</td><td>BC</td><td>BG</td><td>R49H1</td><td></td><td>3</td><td>06BC</td><td><input type="button" onclick="modifier1(this);" value="Modifier"/></td></tr>
    -->    	</tbody>
     
        </table>
        <input type="button" value="Supprimer une ligne" onclick="supprimerLigne_indexN()" />
    	<script>
                    function modifier1(obj) {
                            var oElem = obj.parentNode;
                            monElement = obj.parentNode;
                            numLigne = oElem.parentNode.rowIndex;
                            arrayLignes = document.getElementById("tableau").rows;
                            var indicatif = arrayLignes[oElem.parentNode.rowIndex].cells[0].innerHTML;
                            var etd = arrayLignes[oElem.parentNode.rowIndex].cells[1].innerHTML;
                            var adep = arrayLignes[oElem.parentNode.rowIndex].cells[2].innerHTML;
                            var ades = arrayLignes[oElem.parentNode.rowIndex].cells[3].innerHTML;
                            var detail_pln = arrayLignes[oElem.parentNode.rowIndex].cells[4].innerHTML;
                            var iff_sif = arrayLignes[oElem.parentNode.rowIndex].cells[5].innerHTML;
                            var nb_ac = arrayLignes[oElem.parentNode.rowIndex].cells[6].innerHTML;
                            var num = arrayLignes[oElem.parentNode.rowIndex].cells[7].innerHTML;
                            var element = document.getElementById("indicatif");
                            element.value = indicatif;
                            var element1 = document.getElementById("ETD");
                            element1.value = etd;
                            var element2 = document.getElementById("ADEP");
                            element2.value = adep;
                            var element3 = document.getElementById("ADES");
                            element3.value = ades;
                            var element4 = document.getElementById("Detail_PLN");
                            element4.value = detail_pln;
                            var element5 = document.getElementById("IFF_SIF");
                            element5.value = iff_sif;
                            var element6 = document.getElementById("Nb_AC");
                            element6.value = nb_ac;
                            var element7 = document.getElementById("num");
                            element7.value = num;
                            document.getElementById("ajout").disabled=true;
                            document.getElementById("modifier2").disabled=false;
                    }
            </script>
    	<script>        
                    function modifierSuite() {
                            arrayLignes[monElement.parentNode.rowIndex].cells[0].innerHTML = document.getElementById("indicatif").value;
                            arrayLignes[monElement.parentNode.rowIndex].cells[1].innerHTML = document.getElementById("ETD").value;
                            arrayLignes[monElement.parentNode.rowIndex].cells[2].innerHTML = document.getElementById("ADEP").value;
                            arrayLignes[monElement.parentNode.rowIndex].cells[3].innerHTML = document.getElementById("ADES").value;
                            arrayLignes[monElement.parentNode.rowIndex].cells[4].innerHTML = document.getElementById("Detail_PLN").value;
                            arrayLignes[monElement.parentNode.rowIndex].cells[5].innerHTML = document.getElementById("IFF_SIF").value;
                            arrayLignes[monElement.parentNode.rowIndex].cells[6].innerHTML = document.getElementById("Nb_AC").value;
                            arrayLignes[monElement.parentNode.rowIndex].cells[7].innerHTML = document.getElementById("num").value;
                            document.getElementById("ajout").disabled=false;
                            document.getElementById("modifier2").disabled=true;
                            document.getElementById("myForm").reset();
                    }
            </script>
    	<script>
                    function ajouterLigne()
                    {
                            var tableau2 = document.getElementById("tableau");
                            var ligne = tableau2.insertRow(-1);//on a ajouté une ligne
                            var colonne1 = ligne.insertCell(0);
                            colonne1.innerHTML += document.getElementById("indicatif").value;
                            var colonne2 = ligne.insertCell(1);
                            colonne2.innerHTML += document.getElementById("ETD").value;
                            var colonne3 = ligne.insertCell(2);
                            colonne3.innerHTML += document.getElementById("ADEP").value;
                            var colonne4 = ligne.insertCell(3);
                            colonne4.innerHTML += document.getElementById("ADES").value;
                            var colonne5 = ligne.insertCell(4);
                            colonne5.innerHTML += document.getElementById("Detail_PLN").value;
                            var colonne6 = ligne.insertCell(5);
                            colonne6.innerHTML += document.getElementById("IFF_SIF").value;
                            var colonne7 = ligne.insertCell(6);
                            colonne7.innerHTML += document.getElementById("Nb_AC").value;
                            var colonne8 = ligne.insertCell(7);
                            colonne8.innerHTML += document.getElementById("num").value;
                            var colonne9 = ligne.insertCell(8);
                            colonne9.innerHTML += "<input type=\"button\" onclick=\"modifier1(this);\" value=\"Modifier\"/>";
                            document.getElementById("myForm").reset();
                    };
    //              }
                    function supprimerLigne_indexN(){
                            var n;
     
                            // on récupère l'identifiant (id) de la table qui sera modifiée
                            var tableau1 = document.getElementById("tableau");
                            // nombre de lignes dans la table (avant suppression de la ligne n)
                            var nbLignes = tableau.rows.length;
     
                            n = prompt("Numéro de la ligne à supprimer ?\nEntrez une valeur entre 1 et " + (nbLignes-1));
     
                            if (n < 1 || n > (nbLignes))
                            {
                                    alert("Erreur, valeur incorrecte");
                                    return;
                            }
     
                            if (tableau1.rows.length)
                            {
                                    tableau1.deleteRow(n); // suppression d'une ligne à l'index n
                            }
                    }
        </script>
        <script>
                    var index
                    function  sort_int(p1,p2) { return p1[index]-p2[index]; }                       //fonction pour trier les nombres
                    function sort_char(p1,p2) { return ((p1[index]>=p2[index])<<1)-1; }     //fonction pour trier les strings
     
                    function TableOrder(e,Dec)  //Dec= 0:Croissant, 1:Décroissant
                    { //---- Détermine : oCell(cellule) oTable(table) index(index cellule) -----//
                            var FntSort = new Array()
                            if(!e) e=window.event
                            for(oCell=e.srcElement?e.srcElement:e.target;oCell.tagName!="TH";oCell=oCell.parentNode);       //determine la cellule sélectionnée
                            for(oTable=oCell.parentNode;oTable.tagName!="TABLE";oTable=oTable.parentNode);                          //determine l'objet table parent
                            for(index=0;oTable.rows[0].cells[index]!=oCell;index++);                                                                        //determine l'index de la cellule
     
                    //---- Copier Tableau Html dans Table JavaScript ----//
                            var Table = new Array()
                            for(r=1;r<oTable.rows.length;r++) Table[r-1] = new Array()
     
                            for(c=0;c<oTable.rows[0].cells.length;c++)      //Sur toutes les cellules
                            {       var Type;
                                    objet=oTable.rows[1].cells[c].innerHTML.replace(/<\/?[^>]+>/gi,"")
                                    if(objet.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) { FntSort[c]=sort_char; Type=0; } //date jj/mm/aaaa
                                    else if(objet.match(/^[0-9£?$\.\s-]+$/))               { FntSort[c]=sort_int;  Type=1; } //nombre, numéraire
                                    else                                                                                    { FntSort[c]=sort_char; Type=2; } //Chaine de caractère
     
                                    for(r=1;r<oTable.rows.length;r++)               //De toutes les rangées
                                    {       objet=oTable.rows[r].cells[c].innerHTML.replace(/<\/?[^>]+>/gi,"")
                                            switch(Type)            
                                            {       case 0: Table[r-1][c]=new Date(objet.substring(6),objet.substring(3,5),objet.substring(0,2)); break; //date jj/mm/aaaa
                                                    case 1: Table[r-1][c]=parseFloat(objet.replace(/[^0-9.-]/g,'')); break; //nombre
                                                    case 2: Table[r-1][c]=objet.toLowerCase(); break; //Chaine de caractère
                                            }
                                            Table[r-1][c+oTable.rows[0].cells.length] = oTable.rows[r].cells[c].innerHTML
                                    }
                            }
     
                    //--- Tri Table ---//
                            Table.sort(FntSort[index]);
                            if(Dec) Table.reverse();
     
                     //---- Copier Table JavaScript dans Tableau Html ----//
                            for(c=0;c<oTable.rows[0].cells.length;c++)      //Sur toutes les cellules
                                    for(r=1;r<oTable.rows.length;r++)               //De toutes les rangées 
                                            oTable.rows[r].cells[c].innerHTML=Table[r-1][c+oTable.rows[0].cells.length];  
                    }
            </script>
      </body>
    </html>

    Je vous remercie par avance de votre aide

    Cordialement,

  2. #2
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 211
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 211
    Par défaut
    Bonjour,
    ne fixe pas de dimensions à tes <td> et supprime le table-layout: fixed du CSS de la <table>.

  3. #3
    Membre averti
    Inscrit en
    Octobre 2010
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 26
    Par défaut
    Bonjour,

    Je te remercie pour ton message mais cela ne donne pas le résultat escompté. Je vais essayer de te poster une impression d'écran dans la journée pour que tu voies le résultat.

    Cordialement,

Discussions similaires

  1. Affichage dynamique d'une colonne
    Par kimlee dans le forum MFC
    Réponses: 5
    Dernier message: 27/12/2012, 10h03
  2. Rafraichissement dynamique d'une colonne calculée sur une liste
    Par jsflamar dans le forum Développement Sharepoint
    Réponses: 0
    Dernier message: 24/11/2011, 17h26
  3. Réponses: 0
    Dernier message: 03/10/2011, 09h55
  4. Réponses: 6
    Dernier message: 15/12/2009, 17h01
  5. Réponses: 11
    Dernier message: 02/06/2007, 01h55

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