Filter records of the query

Filter records of the query

mmarroquinmmarroquin Posts: 19Questions: 11Answers: 0

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

  • allanallan Posts: 61,759Questions: 1Answers: 10,111 Site admin
    Answer ✓

    In this case you would use the Editor where() method.

    Something like:

    ->where( 'fecha', $_POST['inicio'] )
    // etc
    

    You would also need to POST the data to the server which you can do using ajax.data.

    Allan

  • mmarroquinmmarroquin Posts: 19Questions: 11Answers: 0
    edited February 2015

    Thanks Allan

This discussion has been closed.