laravel 创建50000条记录后出现DataTables错误

mo49yndu  于 2023-01-21  发布在  其他
关注(0)|答案(1)|浏览(181)

我在Laravel中使用DataTables,在创建50000条记录后,我遇到了这个错误:

DataTables warning: table id=employee_table - Ajax error. For more information about this error, please see http://datatables.net/tn/7

当我有200条记录时,它曾经工作得很好,但是现在它抛出了这个错误。如何修复它?我的脚本:

$(document).ready(function() {
        var table = $('.employee_datatable').DataTable({
            processing: true,
            serverSide: true,
            ajax: "{{ route('admin.employees.index') }}",
            columns: [
                {data: 'image_path', name: 'image_path',  orderable: false, searchable: false},
                {data: 'name', name: 'name'},
                {data: 'position', name: 'position'},
                {data: 'recruitment_date', name: 'recruitment_date'},
                {data: 'phone_number', name: 'phone_number'},
                {data: 'email', name: 'email'},
                {data: 'payment', name: 'payment',  render: $.fn.dataTable.render.number( ',', '.', 3, '$')},
                {data: 'action', name: 'action', orderable: false, searchable: false},
            ]
        });

    });

用于调用DataTable的索引函数:

public function index(Request $request)
    {
        if ($request->ajax()) {
            $data = Employee::with('position')->select('id','name','email', 'position_id', 'image_path', 'recruitment_date',
            'phone_number', 'payment')->get();
            return Datatables::of($data)->addIndexColumn()
            ->addColumn('position', function (Employee $employee) {
                return $employee->position->name;
            })->addColumn('image_path', function ($data) { $url=asset("images/$data->image_path");
                return '<img src='.$url.' class="rounded-circle" width="40" align="center" />'; })
            ->addColumn('action', function($data){
                    $button = '<a href="/admin/employees/'. $data->id .'/edit"  class="edit btn btn-primary btn-sm"> <i class="fas fa-fw fa-edit"></i>Edit</a>';
                    $button .= '        <button type="button" name="edit" id="'.$data->id.'" class="delete btn btn-danger btn-sm"">
                     <i class="fas fa-fw fa-trash"></i> Delete</button>';
                    return $button;
                })->rawColumns(['image_path', 'action'])
                ->make(true);
        }

        return view('admin.employees.index');

    }
vxf3dgd4

vxf3dgd41#

这确实是因为get(),所以现在我的索引函数看起来像这样:

$data = Employee::with('position')->select('id','name','email', 'position_id', 'image_path', 'recruitment_date',
            'phone_number', 'payment');

感谢Manjeet巴纳拉。

相关问题