Hola foreros espero que se encuentren bien, tengo una duda y espero que ustedes me puedan ayudar. estoy creando un sistema web para un colegio en el que trabajo y resulta que estoy ocupando jtable. todo resulta bien el problema es que no puedo filtrar los datos de una tabla ya que solo existe esto para el lenguaje java y asp.net , como podria hacerlo para crear el filtro en php.
tengo un archivo php llamado funcionarios.php que contiene lo siguiente
<html>
<head>
<link href="../themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<link href="../scripts/jtable/themes/metro/blue/jtable.css" rel="stylesheet" type="text/css" />
<script src="../scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="../scripts/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="../scripts/jtable/jquery.jtable.js" type="text/javascript"></script>
<!-- Import CSS file for validation engine (in Head section of HTML) -->
<link href="../css/validationEngine.jquery.css" rel="stylesheet" type="text/css" />
<!-- Import javascript files for validation engine (in Head section of HTML) -->
<script type="text/javascript" src="../js/jquery.validationEngine.js"></script>
<script type="text/javascript" src="../js/jquery.validationEngine-es.js"></script>
</head>
<body>
<div id="PeopleTableContainer" style="width:auto;"></div>
<script type="text/javascript">
$(document).ready(function () {
//Prepare jTable
$('#PeopleTableContainer').jtable({
title: 'Tabla de Funcionarios',
paging: true,
pageSize: 14,
sorting: true,
defaultSorting: 'nombres ASC',
actions: {
listAction: 'accionFuncionarios.php?action=list',
createAction: 'accionFuncionarios.php?action=create',
updateAction: 'accionFuncionarios.php?action=update',
deleteAction: 'accionFuncionarios.php?action=delete'
},
fields: {
rut: {
title: 'Rut',
key: true,
edit: true,
list: true,
width: '15%',
inputClass: 'validate[required]'
},
nombres: {
title: 'Nombres',
width: '15%',
inputClass: 'validate[required]'
},
apellidos: {
title: 'Apellidos',
width: '15%',
inputClass: 'validate[required]'
},
correo: {
title: 'Correo',
width: '17%',
inputClass: 'validate[custom[email]]'
},
telefono : {
title: 'Teléfono',
width: '15%',
inputClass: 'validate[required,custom[phone]]'
},
estado: {
title: 'Estado',
width: '10%',
type: 'checkbox',
setOnTextClick: false,
values: { 'false': 'Inactivo', 'true': 'Vigente' },
defaultValue: 'true'
}
},
//Initialize validation logic when a form is created
formCreated: function (event, data) {
data.form.validationEngine();
},
//Validate form when it is being submitted
formSubmitting: function (event, data) {
return data.form.validationEngine('validate');
}
});
//Load person list from server
$('#PeopleTableContainer').jtable('load');
//jQuery("#jtable-create-form").validationEngine();
});
</script>
</body>
</html>
y el codigo php que lo recibe y que inteactua con la base de datos lo llame accionFuncionarios.php y contiene lo siguiente.
<?php
try
{
//Open database connection
//Getting records (listAction)
if($_GET["action"] == "list")
{
//Get record count
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM funcionario;"); $recordCount = $row['RecordCount'];
//Get records from database
$result = mysql_query("SELECT * FROM funcionario ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
//Add all records to an array
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult['Result'] = "OK";
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;
}
//Creating a new record (createAction)
else if($_GET["action"] == "create")
{
//Insert record into database
$result = mysql_query("INSERT INTO funcionario(rut, nombres, apellidos, correo, telefono, estado) VALUES('" . $_POST["rut"] . "', '".$_POST["nombres"]. "', '".$_POST["apellidos"]. "', '".$_POST["correo"]. "', '".$_POST["telefono"]. "' , '".$_POST["estado"]."');");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM funcionario WHERE rut = '".$_POST["rut"]."';");
//Return result to jTable
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
}
//Updating a record (updateAction)
else if($_GET["action"] == "update")
{
//Update record in database
$result = mysql_query("UPDATE funcionario SET rut = '" . $_POST["rut"] . "', nombres = '" . $_POST["nombres"] . "', apellidos = '" . $_POST["apellidos"] . "', correo = '" . $_POST["correo"] . "', telefono = '" . $_POST["telefono"] . "', estado = '" . $_POST["estado"] . "' WHERE rut = '" . $_POST["rut"] . "';");
//Return result to jTable
$jTableResult['Result'] = "OK";
}
//Deleting a record (deleteAction)
else if($_GET["action"] == "delete")
{
//Delete from database
$result = mysql_query("DELETE FROM funcionario WHERE rut = '" . $_POST["rut"] . "';");
//Return result to jTable
$jTableResult['Result'] = "OK";
}
//Close database connection
}
catch(Exception $ex)
{
//Return error message
$jTableResult['Result'] = "ERROR";
$jTableResult['Message'] = $ex->getMessage();
}
?>
esperando haber entregado la información necesaria para poder obtener ayuda de antemano les agradezco, estaré atento a sus comentarios.
Mod: Obligatorio el uso de etiquetas GeSHi.