$query Results from query() method. */ public function dataTable(QueryBuilder $query): EloquentDataTable { return (new EloquentDataTable($query)) ->editColumn('chart_of_account.name', fn (Product $product) => $product->chartOfAccount?->code ?? '-') ->addColumn( 'action', fn (Product $product) => view('components.datatables.action-button', [ 'edit' => [ 'modal' => 'product-form-modal', 'permission' => auth()->user()->can('update', $product), ], 'delete' => [ 'url' => null, 'title' => __('ui/button.delete'), 'permission' => auth()->user()->can('delete', $product), 'message' => __('ui/confirmation.delete', ['resource' => __('resources.product')]), 'success_message' => __('ui/crud.success.deleted', ['resource' => __('resources.product')]), ], 'table_name' => 'product-table', 'id' => $product->id, ]) ) ->rawColumns(['action']) ->addIndexColumn(); } /** * Get the query source of dataTable. * * @return QueryBuilder */ public function query(Product $model): QueryBuilder { return $model->newQuery()->with(['chartOfAccount', 'pricing']); } /** * Optional method if you want to use the html builder. */ public function html(): HtmlBuilder { return $this->builder() ->setTableId('product-table') ->columns($this->getColumns()) ->minifiedAjax() ->orderBy(1) ->layout([ 'topStart' => [ 'className' => 'col-md-auto me-auto d-flex flex-sm-row flex-column justify-content-center justify-content-md-start align-items-center align-items-md-start gap-1', 'features' => ['buttons', 'pageLength'], ], 'topEnd' => [ 'className' => 'col-md-auto ms-auto d-flex flex-sm-row flex-column justify-content-center justify-content-md-end align-items-center align-items-md-start gap-1', 'features' => ['search'], ], 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->parameters([ 'language' => [ 'search' => '', 'searchPlaceholder' => __('ui/button.lookup'), ], 'scrollX' => true, 'scrollCollapse' => true, 'responsive' => true, ]) ->buttons([ Button::make('reload') ->text(svg('tabler-reload', ['width' => 16, 'height' => 16])->toHtml()) ->addClass('btn-sm'), ]); } /** * Get the dataTable columns definition. */ public function getColumns(): array { return [ Column::computed('DT_RowIndex') ->title('#') ->searchable(false) ->orderable(false), Column::make('code') ->title(__('domains/billing/field.product.code')), Column::make('name') ->title(__('domains/billing/field.product.name')), Column::make('chart_of_account.name') ->title(__('domains/billing/field.product.coa')), Column::computed('action') ->title(__('ui/label.actions')) ->exportable(false) ->printable(false) ->width(60) ->addClass('text-center'), ]; } /** * Get the filename for export. */ protected function filename(): string { return 'ProductDataTable_' . date('YmdHis'); } }