Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data does not appear - laravel 10 CRUD with DataTables Editor. #3193

Open
yofandi opened this issue Nov 12, 2024 · 0 comments
Open

Data does not appear - laravel 10 CRUD with DataTables Editor. #3193

yofandi opened this issue Nov 12, 2024 · 0 comments

Comments

@yofandi
Copy link

yofandi commented Nov 12, 2024

Initially if I use the user model it can work well, but when I start with another table. For example, I created a classes table, when I tried it the data didn't appear and didn't produce any errors at all

Code snippet of problem

namespace App\DataTables;

use App\Models\Class as Classes;
use Illuminate\Database\Eloquent\Builder as QueryBuilder;
use Yajra\DataTables\EloquentDataTable;
use Yajra\DataTables\Html\Builder as HtmlBuilder;
use Yajra\DataTables\Html\Button;
use Yajra\DataTables\Html\Column;
use Yajra\DataTables\Html\Editor\Editor;
use Yajra\DataTables\Html\Editor\Fields;
use Yajra\DataTables\Services\DataTable;

class ClassesDataTable extends DataTable
{
/**

  • Build the DataTable class.
  • @param QueryBuilder $query Results from query() method.
    */
    public function dataTable(QueryBuilder $query): EloquentDataTable
    {
    return (new EloquentDataTable($query))
    ->addColumn('action', 'classes.action')
    ->setRowId('id');
    }

/**

  • Get the query source of dataTable.
    */
    public function query(Classes $model): QueryBuilder
    {
    return $model->newQuery();
    }

/**

  • Optional method if you want to use the html builder.
    */
    public function html(): HtmlBuilder
    {
    return $this->builder()
    ->setTableId('classes-table')
    ->columns($this->getColumns())
    ->minifiedAjax()
    //->dom('Bfrtip')
    ->orderBy(1)
    ->selectStyleSingle()
    ->buttons([
    Button::make('excel'),
    Button::make('csv'),
    Button::make('pdf'),
    Button::make('print'),
    Button::make('reset'),
    Button::make('reload')
    ]);
    }

/**

  • Get the dataTable columns definition.
    */
    public function getColumns(): array
    {
    return [
    Column::computed('action')
    ->exportable(false)
    ->printable(false)
    ->width(60)
    ->addClass('text-center'),
    Column::make('id'),
    Column::make('name'),
    Column::make('created_at'),
    Column::make('updated_at'),
    ];
    }

/**

  • Get the filename for export.
    */
    protected function filename(): string
    {
    return 'Classes_' . date('YmdHis');
    }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant