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
| <!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="author" content="Daniel Hagnoul">
<title>Forum jQuery</title>
<link href='http://fonts.googleapis.com/css?family=Sofia|Ubuntu:400|Kreon'>
<link rel="stylesheet" href="http://danielhagnoul.developpez.com/styles/dvjhRemBase.css">
<style>
.hyphens { -moz-hyphens: auto; -webkit-hyphens: auto; -ms-hyphens: auto; hyphens: auto; }
article { display: table-cell; text-align: justify; /*border:0.1rem dotted grey;*/ }
.table1 { border-collapse: separate; border-spacing: 3rem; }
.ligne { display: table-row; }
.table1 .ligne { min-height: 25rem; }
.table1 article { width: 40rem; vertical-align: top; }
/* TEST */
th { min-width: 10rem; }
table.tablesorter {
width:95%;
margin:12px auto;
/* table-layout = problèmes */
empty-cells:show;
border-collapse:collapse;
border-spacing:0px;
border-width:1px;
border-style:solid;
border-color:#666666;
background-color:#CDCDCD;
color:#000000;
font-size:0.9em;
font-style:normal;
font-weight:normal;
line-height:normal;
letter-spacing:normal;
}
table.tablesorter caption {
caption-side:top;
padding-top:6px;
padding-bottom:6px;
text-align:center;
font-size:1.2em;
font-style:oblique;
font-weight:bold;
line-height:normal;
letter-spacing:0.2em;
color:#000000;
}
table.tablesorter thead tr th {
border-width:1px;
border-style:solid;
border-color:#999999;
background-color: #e6eeee;
color:#000000;
padding:6px;
text-align:center;
font-size:0.9em;
font-style:normal;
font-weight:bold;
line-height:1.8em;
letter-spacing:normal;
}
table.tablesorter tfoot tr th {
border-width:1px;
border-style:solid;
border-color:#999999;
background-color: #e6eeee;
color:#000000;
padding:6px;
text-align:left;
font-size:0.9em;
font-style:italic;
font-weight:normal;
line-height:1.4em;
letter-spacing:normal;
}
table.tablesorter thead tr .header {
background-image:url(../images/bg.gif);
background-repeat: no-repeat;
background-position:left;
cursor: pointer;
}
table.tablesorter tbody td {
border-width:1px;
border-style:solid;
border-color:#999999;
background-color:#FFFFFF;
color:#000000;
vertical-align:middle;
padding:6px;
text-align:left;
font-size:0.9em;
font-style:normal;
font-weight:normal;
line-height:1.2em;
letter-spacing:normal;
}
</style>
</head>
<body>
<h1>Forum jQuery</h1>
<h2>Titre 2</h2>
<section class="conteneur">
<section class="table1">
<section class="ligne">
<article>
</article>
</section>
</section>
</section>
<footer itemscope itemtype="http://danielhagnoul.developpez.com/">
<time datetime="2012-12-03T12:03:26.332+01:00" pubdate>2012-12-03T12:03:26.332+01:00</time>
<span itemprop="name">Daniel Hagnoul</span>
<a href="http://www.developpez.net/forums/u285162/danielhagnoul/" itemprop="url">@danielhagnoul</a>
<a href="http://danielhagnoul.developpez.com/" itemprop="url">Mon cahier dexercices</a>
<a href="http://javascript.developpez.com/faq/jquery/" itemprop="url">FAQ</a>
<a href="http://javascript.developpez.com/cours/?page=frameworks#jquery" itemprop="url">Tutoriels</a>
</footer>
<script src="http://danielhagnoul.developpez.com/lib/raphael-min.js"></script>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/color/jquery.color-2.1.1.min.js"></script>
<!--https://github.com/jquery/jquery-color-->
<script src="http://danielhagnoul.developpez.com/lib/dvjh/base.js"></script>
<script>
"use strict";
/***************************
* Speed Table By SpaceFrog *
**************************/
/*
* Ajout de thead by Daniel Hagnoul 2012-12-03
* Retrait du style : newCell.style.border
*/
function buildTable(destObj, nbrLines, nbrCells){
var baliseTable = document.createElement('table'),
baliseThead = document.createElement('thead'),
baliseTbody = document.createElement('tbody');
baliseTable.id = "foo";
var newLine = document.createElement('tr');
for(var l=0; l < nbrCells; l++){
var newCell = document.createElement('th');
newCell.appendChild(document.createTextNode('Titre_' + l));
newLine.appendChild(newCell);
}
baliseThead.appendChild(newLine);
baliseTable.appendChild(baliseThead);
for(var i = 0; i < nbrLines; i++){
addLine(baliseTbody, nbrLines, nbrCells, i);
}
baliseTable.appendChild(baliseTbody);
destObj.appendChild(baliseTable);
document.close();
}
function addLine(destBody, nbrLines, nbrCells, contenu){
var newLine = document.createElement('tr');
for(var l=0; l < nbrCells; l++){
addCells(newLine, contenu + '_' + l);
}
destBody.appendChild(newLine);
}
function addCells(destLine, contenu){
var newCell = document.createElement('td');
// newCell.style.border = "solid 1px gray";
newCell.appendChild(document.createTextNode('Cellule ' + contenu));
destLine.appendChild(newCell);
}
//-----------------------
$(function(){
/*
* On construit, très rapidement, une grande
* table de test d'ID "foo", en utilisant la
* fonction BuildTable de @SpaceFrog.
*
* (élément du DOM, nb de lignes, nb de colonnes)
*
* $( "article:first" )[ 0 ] est l'élément du DOM
* contenu dans l'objet jQuery.
*/
buildTable( $( "article:first" )[ 0 ], 20, 6 );
/*
* Bouton modifier
* La méthode index permet d'attribuer un
* numéro au lignes de la table.
*/
var jObjBtn = $( "<button/>", {
"text" : "Modifier",
"css" : {
"margin" : "6px"
},
"click" : function( e ){
var jObjTr = $( this ).parents( "tr" ),
index = $( "#foo > tbody > tr ").index( jObjTr );
/*
* Traitement, votre code
* index va de 0 à n
*/
console.log( "La ligne qui contient la cellule = ", jObjTr.children( ":first" ).text(), ", porte le numéro = ", index + 1 );
}
});
/*
* Ajout d'une classe à la table
* et d'un bouton "Modifier" dans
* la dernière cellule de chaque
* ligne du tbody.
*/
$( "#foo" )
.addClass( "tablesorter" )
.find( "tbody > tr" )
.each( function( i, item ){
$( "td:last", item ).append( jObjBtn.clone( true, true ) );
});
});
</script>
</body>
</html> |
Partager