vendredi 30 septembre 2016

Yajra datatable search returns no data

I rendered a server side datatable using Yajra in Laravel 5.1. But when i am trying to search any record, using the search box, I get the following message, No matching records found. I tried adding searchable: true in all the columns but still the problem is same.

Please help me with this issue.

My code:

JS:

$(function () {
        var table = $('#people-table').DataTable({
            "order": [[ 0, "asc" ]],
            pageLength : 50,
            lengthMenu : [50,100,150],
            "scrollX": false,
            "processing": true,
            "serverSide": true,
            "ajax": {
                url: "/people-view",
                data: {'_token': "{!! csrf_token() !!}",'company_name':""},
                method: "post"
            },
            columns: [
                {data: getFNameLName, name: 'first_name'},
                {data: 'data.title', name: 'title'},
                {data: 'data.country', name: 'country'}
            ]
        });
    });
    function getFNameLName(data, type, dataToSet) {
        return data.data.first_name + " " + data.data.last_name;
    }

HTML

<table class="display table table-stripped" id="people-table" cellspacing="0"
                                   style="table-layout: auto;">
                                <thead>
                                <tr>
                                    <th>Name</th>
                                    <th>Job Title</th>
                                    <th>Country</th>
                                </tr>
                                </thead>
                            </table>

Routes:

Route::post('people-view','UserController@peoplesDetails');

Controller:

public function peoplesDetails(Request $request)
    {
        $company_name = $request->input('company_name');
        $people_detail = \App\People::where('data.current_companies.company', '=', $company_name)->
                        select('data.first_name', 'data.last_name', 'data.title', 'data.country')
                            ->take(150)->get();
        return Datatables::of($people_detail)
        ->addColumn('name',function ($people_detail){
            return $people_detail->first_name . " " . $people_detail->last_name;
        })
            ->addColumn('title',function ($people_detail){
                return $people_detail->title;
            })
            ->addColumn('country',function ($people_detail){
                return $people_detail->country;
            })->make(true);
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire