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){...} );
.– Daniel
If you prefer to reload the page, you can include a form with all fields
hidden
and give asubmit()
in it.– Daniel
Yes, exactly @Daniel, but as such, use the name inputs, one by one?
– gabrielfalieri
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 offind
you usedados[$(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.– Daniel
Dude, doing the tests I saw that works perfectly... it returns me arrays, not hard to treat no
– gabrielfalieri
Okay, now the doubt I didn’t understand. You want to know the query you will use?
– Daniel
No.. know if my data was coming in php, I managed to get
– gabrielfalieri
So leave the solution as an answer to your question, so the guys who arrive at it will already have an answer.
– Daniel