mercredi 15 janvier 2020

How to fix "Requested unknown parameter '0' for row 0, column 0" with laravel yajra datatables

I am using laravel yajra datatables with polymorphic relationship. The table not working properly. Here are troubles:

  • Too slow loading (only 81 records actually for all, and page length set to 10);
  • Loader not showing;
  • Data not appearing in table;
  • Getting error : Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
  • Do not know how to add classes to my table columns according to user permission.
  • How to keep my checkbox colum added like :

    $("#mytable").DataTable({ columnDefs: [{ targets: 'select-checkbox', sortable: false }], select: { style: 'multi', selector: 'td:last-child' } });

Here is my laravel code (php):

$query = Book::with('author')->select('*');
    return Datatables::of($query)
        ->editColumn('name', function($row) {
            if($row->author->name !== null){
                return $row->author->name;
            } else {
                return $row->author->pseudo;;
            }
        })        
        ->addColumn('action', function($row){
            $btn = '<a href="/show'.$row->id.'">Display</a>';
            return $btn;
        })
        ->addColumn('selected', function($row){
            return '<input name="selected[]" value="'.$row->id.'" type="checkbox" class="select-checkbox w-100"/>';
        })   
        ->rawColumns(['action', 'selected'])
        ->make(true);

Here is my Datatable initialization code (js):

var table = $('#mytable').DataTable({
                processing: true,
                serverSide: true,
                stateSave: true
                ajax: 'myajaxurl/datatable',
                language: {
                    "url": "/json/dataTables.french.lang.json"
                },
                pageLength: 10,
                lengthMenu: [ 5, 10, 15, 25, 50, 100 ],
                responsive: true,
                "columns": [
                    {data: 'id', name: 'id', visible: false},
                    {data: 'author_id', name: 'author_id', visible: false},
                    {data: 'name', name: 'name', sClass:'name'},
                    {data: 'action', name: 'action', searchable: false},
                    {data: 'selected', name: 'selected', searchable: false, sortable: false},
                ]});


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/387FapR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire