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
| $.ajax({
type: "POST",
url: "Default.aspx/GetColModelBovins",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (data) {
// récupération du colModel
var colModelBovins = data.d.colonnes;
// création de la grille
grille = $("#tab-bovins").jqGrid({
url: "Default.aspx/GetBovins",
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
datatype: "json",
mtype: "POST",
colModel: colModelBovins,
serializeGridData: function (postData) {
return JSON.stringify(postData); // permet d'atteindre la fonction GetColModelBovins
},
jsonReader: {
id: "id",
root: "d.rows",
repeatitems: true
},
loadonce: true,
autowidth: true,
shrinkToFit: false,
recordtext: "Bovins {0} - {1} sur {2}",
rowNum: 30,
rowList: [30, 50, 100, 10000],
pager: '#tab-bovins-pager',
viewrecords: true,
emptyrecords: "Aucuns bovins",
//affichage de la colonne [+]
subGrid: true,
subGridBeforeExpand: function (subgrid_id, row_id) {
//sur click du bouton plus on génére la grille des visites sur le bovins
//paramètres à envoyer à la requete REQ_VISITES
var nutrav = $(this).jqGrid('getCell', row_id, 'nutrav');
//variable préparatoire à la mise en forme json
var param = {
Nutrav: nutrav
}
//Grille Visite
var grilleVisite;
$.ajax({
type: "POST",
url: "Default.aspx/GetColModelVisites",
dataType: 'json',
//Génération du JSON
//envoi du paramètre a la requête REQ_VISITES
data: JSON.stringify(param),
contentType: 'application/json; charset=utf-8',
success: function (data) {
//évaluation du script retourné
eval(data.d);
// récupération du colModel
var colModelVisites = data.d.colonnes;
//Création de la grille
$('#' + row_id).html('<td><td colspan="4"><table id="tab-visites" style="width:100%;></table><div id="tab-visites-pager"></div></td></td>');
grilleVisite = $("#tab-visites").jqGrid({
url: "Default.aspx/GetVisites",
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
datatype: "json",
mtype: "POST",
colModel: colModelVisites,
jsonReader: {
id: "id",
root: "d.rows",
repeatitems: true
},
loadonce: true,
autowidth: true,
height: '100%',
shrinkToFit: false,
recordtext: "Visites {0} - {1} sur {2}",
rowNum: 20,
rowList: [20, 50, 100, 10000],
pager: '#tab-visites-pager',
viewrecords: true,
subGridRowCollapsed: function (subgrid_id, rowid){
//jQuery("#tab-bovins").hideCol('subgrid');
//jQuery('#tab-visites').remove();
},
emptyrecords: "Aucune visite",
postData: JSON.stringify(param),
loadError: function (xhr, status, error) {
alert("Chargement impossible..");
console.log(status, error);
}
});
},
error: function (xhr, status, error) {
alert("Un problème est survenu : " + error);
}
});
},
loadComplete: function () {
$("option[value=10000]").text('Tout');
$(".ui-jqgrid-bdiv").css("height", $(window).height() - $("#gbox_tab-bovins").offset().top - 100);
}
});
},
error: function (xhr, status, error) {
alert("Un problème est survenu : " + error);
}
}); |
Partager