0

I'm using datatables.net and its plugin Editor I'm having trouble when i edit a field.

in edit field i've got L& #0039;ALSACE instead of L'ALSACE

enter image description here

Instead of clean uft8 i've got an html encoded char.

What do i do wrong ?

Laravel is 6.5.0. MySQL db is utf8mb4, collation utf8mb4_unicode_ci; laravel database config file is well configured ('charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci') Editor is version 1.9.2 Datatables is version 1.10.20 yajra/laravel-datatables-oracle v9.7.1

Laravel controler (ajax get Json Data)

public function getList()
{
    $regie = Regie::select(['id','libelle','web'])
        ->where('typemedia_id', '=', 8)
        ->with('grouperegies');

        return Datatables::make($regie)->toJson();
 }

Laravel Blade (view) js part

var editor;
  $(document).ready( function () {
    editor = new $.fn.dataTable.Editor( {
    ajax:  '{{ url('regiepqr-list') }}',
    table: '#laravel_datatable',
    idSrc:  'id',
    fields: [
        { label: 'id', name: 'id' }, 
          { label: 'libelle', name:'libelle'},
          { label: 'web', name:'web'}
    ]
} );
$('#laravel_datatable').on( 'click', 'tbody td:not(:first-child)', function (e) {
        editor.inline( this );
    } );
$('#laravel_datatable').DataTable({
      processing: true,
      serverSide: true,
      responsive: true,
      select: true,
      dom: 'Bfrtip',
      buttons: [
        { extend: 'create', editor: editor },
        { extend: 'edit',   editor: editor },
        { extend: 'remove', editor: editor }
    ],
      language: {"url": "https://cdn.datatables.net/plug-ins/1.10.20/i18n/French.json"},
      ajax: "{{ url('regiepqr-list') }}",
      columns: [
          { data: 'id' }, 
          { data: 'libelle'},
          { data: 'web' }
      ]
    });
  });

A dd( Datatables::make($regie)->toJson()) in my controler show me that data are already in html encode char. is it normal ?

Many thank's B.

0

1 Answer 1

0

After further investigation, the trouble seems to be with yajra/laravel-datatables (any other laravel class work's fine).

I try to config vendor\yajra\laravel-datatables-oracle\src\config\datatables.php

'json' => [ 'header' => ['Content-Type' => 'application/json;charset=utf8'], 'options' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES , ],

or

'header' => ['Content-Type' => 'text/html; charset=UTF-8'],

but no success (the header change but not the JSON)

The workaround is to use ->rawColumns().

    return Datatables::of($regie)->rawColumns(['libelle'])->make(true);

It's working but it's not very convenient : i have to think about each column... any other ideas ? Thank's

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.