how to get the return of an array sent by a datatable ajax?

Asked

Viewed 265 times

0

I am using the datatables to show my table data... and in it I need to make some simultaneous custom filters. I basically until then, I’m sending the requisition in the following way:

 $('#btnFiltro').on( 'click', function () {   // for text boxes
      var dados = new Array();
      $('#frmReportPartners').find(":text:visible,:checkbox:checked,select:visible").each(function(v) {
         dados[v] = $(this).val();
      });
      dataTable.columns().search(dados).draw();
      console.log(dados);    
  });|

Now, after this submission, which way should I use to retrieve and treat such information sent, since a record only, I get so:

if(!empty($requestData['columns'][10]['search']['value'])) {
    $sql .= " AND data_de_aluguel LIKE '" . $requestData['columns'][10]['search']['value'] . "%'";
}
  • When you click the filter button, you’re going through checkboxes, radios, etc and picking up the data, right? I advise instead of using the index in the function $.each() use the name of <input>, thus: dados[$(this).attr('name')]. Then make an ajax for your server with the data $.get( "test.php", dados, function(dadosFiltrados){...} );.

  • If you prefer to reload the page, you can include a form with all fields hidden and give a submit() in it.

  • Yes, exactly @Daniel, but as such, use the name inputs, one by one?

  • No, there in the same loop. Where you take the value of checkboxes, use an object instead of array (var dados = {}) and in the callback of find you use dados[$(this).attr('name')] = $(this).val(); that there it will create a mounted object, with the name of the fields and the values. It is easier to handle the server side.

  • Dude, doing the tests I saw that works perfectly... it returns me arrays, not hard to treat no

  • Okay, now the doubt I didn’t understand. You want to know the query you will use?

  • No.. know if my data was coming in php, I managed to get

  • So leave the solution as an answer to your question, so the guys who arrive at it will already have an answer.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.