Hi, I'm trying to get work this code:
$("#list").jqGrid({
url: 'docente.php',
datatype: 'json',
mtype: 'POST',
postData: {c : "", n: "", a: "", d: "", t: "", e: "", f: "", g: $('#selectD').value(), p: "", call: "report"},
colNames: ['Cédula','Nombres', 'Apellidos', 'Dirección', 'E-mail','Teléfono', 'Profesión'],
colModel: [
{ name:'rows.cedula', index: 'cedula', search:true, jsonmap: 'cedula', width: 150, align: 'left', sortable:true},
{ name:'rows.nombre', index: 'nombre', jsonmap: 'nombre', width: 150, align: 'left'},
{ name:'rows.apellido', index: 'apellido', jsonmap: 'apellido', width: 240, align: 'left'},
{ name:'rows.direccion', index: 'direccion', jsonmap: 'direccion', width: 330, align: 'left'},
{ name:'rows.email', index: 'email', jsonmap: 'email',width: 200, align: 'left'},
{ name:'rows.telefono', index: 'telefono', jsonmap: 'telefono', width: 170, align: 'left'},
{ name:'rows.descripcion_profesion', index: 'descripcion_profesion', jsonmap: 'descripcion_profesion',width: 120, align: 'left'}],
pager: '#pager',
rowNum: 8,
autowidth: true,
rowList: [10, 20],
sortname: 'cedula',
sortorder: 'asc',
viewrecords: true,
caption: 'Docentes',
jsonReader : {
root: "rows",
repeatitems: false
},
height: 350,
width: 900
});
$("#list").jqGrid('navGrid','#pager',{search:true, searchtext: "buscar",edit:false,add:false,del:false});
The HMTL I'm using:
<div id="reporte">
<table id="list"></table>
<div id="pager">
</div>
<div>
And the PHP code:
$total_pages = 0;
$limit=10;
$count = Profesor::CountAll();
if($count> 0)
$total_pages= ceil($count/$limit);
else
$total_pages=0;
$cnx = new PDO("mysql:host=localhost;dbname=appsms","root","");
$rows = array();
$strQuery="select cedula, nombre, apellido, direccion, telefono, email, descripcion_profesion from Profesor join Profesion on " .
" (profesor.profesion_id = profesion.id) and (profesor.grado_id_grado = '" .$this->grado .
"') order by cedula;";
$stmt = $cnx->prepare($strQuery);
$stmt->execute(array("reporte"));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$response->page = 1;
$response->total= $total_pages;
$response->records = sizeof($rows);
$i=0;
foreach($rows as $result){
$response->rows[$i] = $result;
$i++;
}
echo json_encode($response);
The JSON I get:
{"page":1,"total":1,"records":2,
"rows":[{"cedula":"v-108984103","nombre":"Soneia","apellido":"Rond\u00f3n Contreras","direccion":"El Rosal, calle 2-44","telefono":"04544247008457","email":"foo@yahoo.es","descripcion_profesion":"Docente"},
{"cedula":"v-135254741","nombre":"Judith","apellido":"Rangel M\u00e1rquez","direccion":"Sabaneta","telefono":"04247644152499","email":"","descripcion_profesion":"Docente"}]}
It loads the query from PHP but the search option doesn't work neither the sorting function on "cedula"'s column. What I need to do?. Thanks in advance.