Laravel-datatables: How to filter or search the editColumn ?

Created on 13 Sep 2017  路  3Comments  路  Source: yajra/laravel-datatables

@yajra ,
Can I ask some help please, How can I filter or search in my editColumn

here is my code

     $model = Po::select(['id','vendor_id','amount']);

    return Datatables::of($model)
            ->editColumn('vendor_id',function( $m ){
                return Vendor::find($m->vendor_id)->name;
            })

         ->filterColumn('vendor_id', function($query, $keyword) {
                $sql = "like ?"; //here I have no idea what to do.
                $query->whereRaw($sql, ["%{$keyword}%"]);
            })
         ->make(true);

Thank you in advance.

question

All 3 comments

Try using eager loading?

     $model = Po::with('vendor')->select(['id','vendor_id','amount']);

    return Datatables::of($model)->make(true);

On you scripts:

columns: [
    {data: 'id'},
    {data: 'vendor.name'},
    {data: 'amount'}
]

Some demo for ref:
http://dt54.yajrabox.com/eloquent/has-one
https://datatables.yajrabox.com/relation/belongs-to

Thank you so much @yajra

can we don't do with
->filterColumn('vendor_id', function($query, $keyword) {
$sql = "like ?"; //here I have no idea what to do.
$query->whereRaw($sql, ["%{$keyword}%"]);
})

? i want to done with this only , please any solution

Was this page helpful?
0 / 5 - 0 ratings