Filter does not work because of return accentuation problem, what to do?

Asked

Viewed 141 times

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: Selecionando o campo com acentuação

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. Imagem com acentuação zoada

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.

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

  • 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.

1 answer

1

I’m not very experienced in this area but maybe give a encodeURIComponent value can solve the problem.

Staying then:

dados[v] = encodeURIComponent($(this).val());

It also had problems with special characters and this function solved the problem.
I hope you solve your problem :D

  • thanks for the tip, I’ll test as soon as I finish my lunch hour

  • Dude, it didn’t work out

Browser other questions tagged

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