yajra / laravel-datatables

jQuery DataTables API for Laravel
https://yajrabox.com/docs/laravel-datatables
MIT License
4.76k stars 858 forks source link

Search not working after modyfying source #3161

Closed Dambar93 closed 2 months ago

Dambar93 commented 4 months ago

When modifying source of dataTable, table search in frontend is not working and returning empty table. Until I'm not writing in search it shows records by filtering. If there is solution to this or I need to use other search tools? Or I'm doing it all wrong?

/**
 * Build the DataTable class.
 *
 * @param QueryBuilder $query Results from query() method.
 */
public function dataTable(QueryBuilder $query): EloquentDataTable
{
    $user = Auth::user();

    $dataTable = new EloquentDataTable($query);

    $dataTable->addColumn('action', 'order.dt.actions')
        ->addColumn('date', function (Order $order) {
            return $order->created_at->format('Y-m-d');
        })
        ->addColumn('car_plate', function (Order $order) {
            return $order->car->number_plate ?? '';
        })
        ->addColumn('id', function (Order $order) {
            return $order->internal_id;
        })
        ->rawColumns(['action']);

    return $dataTable;
}

/**
 * Get the query source of dataTable.
 */
public function query(Order $model): QueryBuilder
{
    $user = Auth::user();
    return $model->where('driver_id', $user->driver_id)
                 ->orWhere('customer_id', $user->customer_id);
}

System details

yajra commented 4 months ago

addColumn disables search/sort by default since it is considered computed and not part of the DB. You can use filterColumn to handle the search instead.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 7 days since being marked as stale.