1
Good morning, stack overflow. I’ve been in trouble for a while where I can’t understand your reason.
I’m working with php datatables, where I do some custom filters. When I select for example 2 checkbox, and click on the button it works perfectly, soon after, if I try to change this filter, unchecking this box and selecting another, it does not filter, but sends the request normally.
Follow some requisition codes
$("#btnFiltrar").on('click',function() {
if($(".chkTipoEducacional").is(':checked')) {
var i =$('.chkTipoEducacional').attr('data-columns');
var v =$('.chkTipoEducacional').val();
dataTable.columns(i).search(v).draw();
console.log(v);
}
});
$("#btnFiltrar").on('click',function() {
if($(".chkTipoComercial").is(':checked')) {
var i =$('.chkTipoComercial').attr('data-columns');
var v =$('.chkTipoComercial').val();
dataTable.columns(i).search(v).draw();
console.log(v);
}
});
$("#btnFiltrar").on('click',function() {
if($(".chkTipoProfissional").is(':checked')) {
var i =$('.chkTipoProfissional').attr('data-columns');
var v =$('.chkTipoProfissional').val();
dataTable.columns(i).search(v).draw();
console.log(v);
}
});
And some examples of php
if(!empty($requestData['columns'][8]['search']['value']) && !empty($requestData['columns'][11]['search']['value']) && !empty($requestData['columns'][12]['search']['value'])){
$sql .= " AND issued_date BETWEEN '".$requestData['columns'][11]['search']['value']."' AND '".$requestData['columns'][12]['search']['value']."'";
}
if(!empty($requestData['columns'][2]['search']['value'])){
$sql.=" AND licensed_version LIKE '".$requestData['columns'][2]['search']['value']."%' ";
}
Thanks in advance!
Try to change attr by prop
– denis
When I put the prop, it searches all filters, not just the selected one.
– Gabriel Falieri
"SELECT razao_social,organization_name, organization_type,edition, licensed_version,issued_date,updates_expiry_date,support_expiry_date,advanced_clients_licensed,users_licensed,id_license FROM license_view WHERE 1 = 1 AND ( users_licensed < '2017-02-05' OR users_licensed > '2017-02-05' ) AND licensed_version LIKE '2017-02-05%' AND organization_type LIKE '2017-02-05%' OR torganization_type LIKE '2017-02-05%' AND Edition LIKE '2017-02-05%' OR Edition LIKE '2017-02-05%' ORDER BY razao_social asc LIMIT 0 ,10 " .
– Gabriel Falieri