JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<table class="table table-condensed tablesorter" id="results">
<thead class="floating-header">
<tr>
<th>NomNomNomNomNomNomNomNom</th>
<th>Âge</th>
<th>Pays</th>
<th>...</th>
<th>...</th>
<th>...</th>
<th>...</th>
<th>Nom</th>
<th>Âge</th>
<th>Pays</th>
<th>...</th>
<th>...</th>
<th>...</th>
<th>...</th>
</tr>
</thead>
<tbody>
<tr>
<td>Carmen</td>
<td>33 ans</td>
<td>Espagne</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>Carmen</td>
<td>33 ans</td>
<td>Espagne</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td>Michelle</td>
<td>26 ans</td>
<td>États-Unis</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>Michelle</td>
<td>26 ans</td>
<td>États-Unis</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td>Michelle</td>
<td>26 ans</td>
<td>États-Unis</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>Michelle</td>
<td>26 ans</td>
<td>États-Unis</td>
<td>...</td>
<td>...</td>
<td>...</td>
...
CSS
#results {
table-layout: fixed;
}
#results th div {
overflow: hidden;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
}
JavaScript
jQuery(function($){
$('#results thead').affix({
offset: {
top: 10
}
});
// Changement de la couleur de fond de l'entête du tableau au scroll
$(window).scroll(function () {
if ($(this).scrollTop() > 90) {
$('#results thead').css('background-color', '#EFEFEF');
}
});
$(".floating-header th").each(function () {
var
$th = $(this),
w = $th.width(), // récupération de la largeur du <th />
text = $th.text(); // récupération du texte du <th />
$th.width(w);
$th.html(
/* on force la largeur en "px" car les "%" ne seront pas pris en compte
* quand le <thead /> sera en "position: fixed;"
*/
$("<div />").text(text).width(w)
);
});
})