0

我尝试使用 yajra 数据表 laravel 我在搜索时遇到问题当我搜索数据时数据表中已经存在它没有工作我已经尝试了文档中的示例但它对我不起作用

有人可以帮帮我吗?教我如何按照我的意思做

示例数据 示例搜索

** 这是我的 javascript 数据表**

let oTable = $("#example1").DataTable({
        responsive: true,
        autoWidth: false,
        processing: true,
        serverSide: true,
        ajax:
        {
            url: '{{ route("data.user.datatables") }}',
            type: 'GET',
            data: function (d) {
                d.filter = $('select[name=filter]').val();
            }
        },
        columns: [
            { data: 'id'},
            { data: function(data, type, row){
                return 'Username : ' + data.username +
                '<br> Email : ' + data.email +
                '<br> Ponsel : ' + data.contact_number;
            },
            name: 'username'
            },
            {
            data: function(data, type, row){
                return 'Register Date : ' +  data.created_at +
                        '<br> Last Login : ' + data.last_login +
                        '<br> App By : '+ data.app_admin +' / '+ data.date_admin_app +
                        '<br> App By : '+ data.login +' || '+ data.status_member;
            },

             name: 'created_at'
            },
            { data: function(data, type, row){
                return 'Saldo : ' +  data.saldo +
                    '<br> Bank Name : ' + data.bank_name +
                    '<br> Account Name : '+ data.account_name +
                    '<br> Account Number : '+ data.account_number;
            },
            name:'saldo'
            },
            { data: 'action', orderable: false, searchable: false}
        ],
        order:[[0,'desc']],

    });

这在我的 Laravel 控制器中

if($request->ajax()):

            $request->validate([
                'filter' => ['string','nullable','alpha'],
            ]);

            if($request->filled('filter')):
                $users = User::query()->where('status_member', $request->filter);
            else:
                $users = User::query();
            endif;
            $data =  Datatables::of($users);
             $data->addIndexColumn();
             $data->addColumn('action', function ($user) {
                return '<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
                            <div class="btn-group" role="group">
                                <button id="btnGroupDrop1" type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action</button>
                                <div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
                                    <a class="dropdown-item modal-edit-user" data-toggle="modal" data-target="#modalEditUser" href="javascript:void(0)" data-id="' . $user->id . '" data-username="' . $user->username . '" >Edit</a>
                                    <a class="dropdown-item" href="#">Dropdown link</a>
                                </div>
                            </div>
                        </div>';
            });
            $data->rawColumns(['action']);
            return $data->make();
        endif;
4

1 回答 1

1

您根本没有向用户查询转发任何内容。

代替

$users = User::query()->where('status_member', $request->filter);
...
$users = User::query();

尝试做

$users = User::where('status_member', $request->filter)->get();
...
$users = User::all();

编辑:

更新您的代码:

{ data: 'action', orderable: false, searchable: false}

{ data: 'action', orderable: false, searchable: true}
于 2020-04-18T14:29:57.793 回答