Server Side Processing - database ID search results only

Server Side Processing - database ID search results only

thinkingmanthinkingman Posts: 3Questions: 1Answers: 0

Hi,

I have implemented datatables in a fairly basic manner setting the serverside processing to true. For reference, I followed this tutorial (mostly) as a guideline since I am using Laravel 7. https://fahmidasclassroom.com/laravel-7-crud-using-datatables/

For some reason, the serverside processing only looks at the database ID in the search. So if I type in the ID of the record then I will get results. But if I look for a string (like someones name) it doesnt return results.

Any pointers on what needs to be allowed to search those other fields? I tried setting the "searchable" to true explicitly but that had no effect.

Thanks!

Answers

  • thinkingmanthinkingman Posts: 3Questions: 1Answers: 0

    I should have added that this is my current script.

    <script type="text/javascript">
    
      $(document).ready(function () {
    
        var table = $('.data-table').DataTable({
          processing: true,
          serverSide: true,
          ajax: "{{ route('customers.index') }}",
          columns: [
            {data: 'id', name: 'id'},
            {data: 'cr_customer', name: 'Number'},
            {data: 'cr_name', name: 'Name'},
            {data: 'cr_area_code', name: 'Area Code'},
            {data: 'cr_phone', name: 'Phone'},
            {data: 'action', name: 'action', orderable: false, searchable: false},
          ]
        });
    
    
      });
    </script>
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    That will be down to the server-side script. Can you post that here too, please,

    Colin

  • thinkingmanthinkingman Posts: 3Questions: 1Answers: 0

    @colin here is the controller function.

    public function index(Request $request)
        {
    
            if ($request->ajax()) {
                $data = Customers::latest()->get();
                return Datatables::of($data)
                    ->addIndexColumn()
                    ->addColumn('action', function($row){
    
                        $action = '<a class="btn btn-info" id="show-customer" data-toggle="modal" data-id='.$row->id.'>Show</a>
    <a class="btn btn-success" id="edit-customer" data-toggle="modal" data-id='.$row->id.'>Edit </a>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <a id="delete-customer" data-id='.$row->id.' class="btn btn-danger delete-customer">Delete</a>';
    
                        return $action;
    
                    })
                    ->rawColumns(['action'])
                    ->make(true);
            }
    
            return view('admin.customers');
    
    
        }
    
  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    edited October 2020

    Thanks for the script. I'm afraid you'll need to contact the author of the Laravel server-side processing library though, as I'm not familiar with their API. At a guess it looks like the action column should be searchable, but I'm really not sure how their API is meant to work.

    Allan

This discussion has been closed.