数据表/编辑器的内联编辑器中的HTML字符集代码

时间:2019-11-08 08:06:59

标签: html laravel datatables character-encoding editor

我正在使用datatables.net及其插件编辑器 我在编辑字段时遇到麻烦。

在我拥有的编辑字段中 L' ALSACE代替L'ALSACE

enter image description here

我有一个HTML编码的char,而不是干净的uft8。

我该怎么办?

Laravel是6.5.0。 MySQL db是utf8mb4,整理utf8mb4_unicode_ci; laravel数据库配置文件配置正确('charset'=>'utf8mb4','collat​​ion'=>'utf8mb4_unicode_ci') 编辑器是1.9.2版 数据表是1.10.20版 yajra / laravel-datatables-oracle v9.7.1

Laravel控制器(ajax获取Json数据)

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

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

Laravel Blade(查看)js部分

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' }
      ]
    });
  });

我的控制器中的dd(Datatables :: make($ regie)-> toJson())向我显示数据已经在html编码char中。正常吗?

非常感谢 B。

1 个答案:

答案 0 :(得分:0)

经过进一步调查,问题似乎出在yajra / laravel-datatables (任何其他laravel类的作品都可以)。

我尝试配置vendor \ yajra \ laravel-datatables-oracle \ src \ config \ datatables.php

backgroundImage: url(process.env.PUBLIC_URL + "/      assets/image_location")

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

但没有成功(标头更改但不是JSON)

解决方法是使用-> rawColumns()。

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

它正在工作,但不是很方便:我必须考虑每列... 还有其他想法吗? 谢谢

相关问题