1
I am working with datatables and php, so server side.
I have been making custom filters with it, everything working ok, with a save exception, the words that have accentuation, does not work in the filter.
Let’s say, I select the following company:
Gabriela and Ana computer LTDA, he will say that the table is empty.
Not understanding the error, I noticed that this only happened with words that had accentuation, so I looked at how was the return.
Clearly, the problem is clear, but I don’t know how to solve it
// code that returns json
$data = array();
while( $row=mysql_fetch_array($rResult) ) { // preparing an array
$nestedData=array();
$nestedData[] = utf8_encode($row["razao_social"]);
$nestedData[] = utf8_encode($row["organization_name"]);
$nestedData[] = $row["organization_type"];
$nestedData[] = $row["edition"];
$nestedData[] = $row["licensed_version"];
$nestedData[] = date("d/m/Y",strtotime($row["issued_date"]));
$nestedData[] = date("d/m/Y",strtotime($row["support_expiry_date"]));
$nestedData[] = date("d/m/Y",strtotime($row["updates_expiry_date"]));
$nestedData[] = $row["advanced_clients_licensed"];
$nestedData[] = $row["users_licensed"];
$nestedData[] = "<a href='detail-license.php?id=".$row['id_license']."'><button class='btn btn-success'><i class='fa fa-list'></i> Detalhes</button></a>";
$nestedData[] = "<a href='download.php?id=".$row['id_license']."'><button class='btn btn-success'><i class='fa fa-download'></i> Download</button></a>";
$data[] = $nestedData;
}
$output = array(
"draw" => intval($_GET['draw']),
"recordsTotal" => $iTotal,
"recordsFiltered" => $iFilteredTotal,
"data" => $data
);
echo json_encode( $output );
// code that sends to php to process the data
$('#btnFiltrar').on( 'click', function () {
var dados = new Array();
$('#frmReportLicense').find(":text:visible,:checkbox:checked,select:visible,input:checked").each(function(v) {
dados[v] = $(this).val();
});
dataTable.columns().search(dados).draw();
console.log(dados);
});
Updating
On my way out I put:
$output = array(
"draw" => intval($_GET['draw']),
"recordsTotal" => $iTotal,
"recordsFiltered" => $iFilteredTotal,
"data" => $data
);
echo json_encode( $output, JSON_UNESCAPED_UNICODE );
It even started returning the right value, only it doesn’t filter.
Possible, if not "quadrupled": https://answall.com/questions/65867/acentua%C3%A7%C3%A3o-no-json, https://answall.com/questions/43193/d%C3%Bavida-com-charset-iso-8859-1-e-utf8, https:///pt.stackoverflowcom/questions/193059/json-em-php-com-campos-existentes-imprimindo-como-null-como-resolver e.
– Inkeliz