laraveldatatableserver-sideyajra-datatable

Yajra DataTables Search Not Working for Modified Column


I'm using Yajra DataTables in Laravel and experiencing issues with the search functionality for the modefied column (HAWB). I've modified the HAWB column definition to display a clickable link, but searching on the actual HAWB value isn't working.

return DataTables::of($data)
    ->addIndexColumn()
    ->addColumn('HAWB', function ($row) {
        $url = route('shipment_tracking') . "?trknbr=" . $row->HAWB;
        return "<a href='$url' target='_blank'>$row->HAWB</a>";
    })
    ->rawColumns(['HAWB'])
    ->make(true);

` $('#airwaybill-tracking').DataTable({ pageLength: 10, processing: true, serverSide: true,

    ajax: route.admin_dashboard,
    columns: [,
        {
            data: 'HAWB',
            name: 'HAWB',
            className: 'text-sm',
        },
     ]`
});

I'm using Laravel with Yajra DataTables package I'm using server-side processing

What I've Tried:

I've verified the route configuration for route('shipment_tracking'). I've used console logs to check the search term and generated URL. I've tried temporarily disabling other column definitions to isolate conflicts.

Expected Behavior: Users should be able to search for HAWB numbers, even though the column displays a link.

Actual Behavior: Searching doesn't seem to work correctly for the HAWB column.


Solution

  • Replace your Controller Code:

    return DataTables::of($data)
        ->addIndexColumn()
        ->editColumn('HAWB', function ($row) {
            $url = route('shipment_tracking') . "?trknbr=" . $row->HAWB;
            return "<a href='$url' target='_blank'>$row->HAWB</a>";
        })
        ->rawColumns(['HAWB'])
        ->make(true);
    

    In then inspite of addColumn use editColumn then you will also be able to search that field