Filter records of the query
Filter records of the query
Hi community, I'm working with DataTables and PHP Sessions, So I need to create a filter with dates ranges, at the begin the current user be able to filter the entries with two inputs date, (fecha and fecha_fin) I'm trying to pass these values for ajax, It's possible to use this function to pass the $_POST values to my /php/table.php:
<script>
$('#example').DataTable( {
dom: "Tfrtip",
ajax: "../php/table.php",
type: "POST",
columns: [
{ data: null, defaultContent: '', orderable: false },
{ data: "FechaFactura" },
{ data: "Vendedor"},
{ data: "FolioFiscal"},
//many data
]
}
</script>
My input dates
<div class="col-md-4">
<div class="col-md-2">
Fecha de Inicio: <input type="date" id="inicio" name="inicio" /> <br/>
Fecha fin: <input type="date" id="fin" name="fin" /> <br />
<input type="submit" value="Consultar" />
</div>
</div>
In my /php/table.php I have this:
At first fecha and fecha_fin will be 0;
$fecha = 0;
$fecha_inicio = 0;
Editor::inst( $db, 'Aseguradoras' )
->fields(
// many fields
Field::inst( 'FechaVale' )
->validator( 'Validate::dateFormat', array(
"format" => Format::DATE_ISO_8601,
"message" => "Please enter a date in the format yyyy-mm-dd"
) )
->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 )
I hope I explained, if they know any other method I hope your help
Thanks in advance
This question has an accepted answers - jump to answer
Answers
In this case you would use the Editor
where()
method.Something like:
You would also need to POST the data to the server which you can do using
ajax.data
.Allan
Thanks Allan