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
|
var header = ['Noms', 'Prénoms', 'Sexe', 'Date de naissance', 'Matricule'];
$(document).ready(function(){
$.ajax({
type: "POST",
url: "staff.php",
data: null,
dataType: "json",
success: function(datas){
$("body").prepend($('<table/>', {'id': "matable", 'class': "tablesorter"}));
$('table').append($('<thead/>'));
$('table').append($('<tfoot/>'));
$('table').append($('<tbody/>'));
$('table').children("thead,tfoot").append(function(){
var tr = $(this).append($('<tr/>'));
$.each(header, function(i, item) {
tr.append($('<th/>', {html: item}));
});
});
$('tbody').append(function(){
$(datas).each(function(i, item) {
var tr = $('tbody').append($('<tr/>'));
tr.append($('<td/>', {html: item.nom}));
tr.append($('<td/>', {html: item.prenom}));
tr.append($('<td/>', {html: (item.sexe==1) ? 'Homme' : 'Femme'}));
tr.append($('<td/>', {html: item.date_naissance}));
tr.append($('<td/>', {html: item.matricule}));
if(i==1000) return false;
});
});
$("table").tablesorter( {sortList: [[0,0], [1,0]]} );
}
});
}); |
Partager