From 0519c597676f846286f5d43bdaf1f0ea7faf60c9 Mon Sep 17 00:00:00 2001
From: raulmainlab <123628611+raulmainlab@users.noreply.github.com>
Date: Wed, 1 Mar 2023 10:43:59 +0100
Subject: [PATCH 1/7] Update html-builder-column-builder.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
questa รจ la proposta giusta per rendere eseguibile il codice da html builder Column Builder
---
html-builder-column-builder.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/html-builder-column-builder.md b/html-builder-column-builder.md
index b523cb0..d7df80a 100644
--- a/html-builder-column-builder.md
+++ b/html-builder-column-builder.md
@@ -30,7 +30,7 @@ $column = Column::make('id')
->title('Id')
->searchable(true)
->orderable(true)
- ->render('function(){}')
+ ->render('\'
\' + (full[\'deleted_at\'] == null ? \'Attivo\' : \'Disattivo\') + \'
\';\'\'' )
->footer('Id')
->exportable(true)
->printable(true);
From 13a0599349ce70f0619f5c95feeeec859652209a Mon Sep 17 00:00:00 2001
From: Arjay Angeles
Date: Thu, 16 Mar 2023 10:43:44 +0800
Subject: [PATCH 2/7] docs: Builder::useVite() helper
---
quick-starter.md | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/quick-starter.md b/quick-starter.md
index fe09e60..15b1c7b 100644
--- a/quick-starter.md
+++ b/quick-starter.md
@@ -196,6 +196,34 @@ use App\Http\Controllers\UsersController;
Route::get('/users', [UsersController::class, 'index'])->name('users.index');
```
+### Use ViteJs / script type defaults to module
+
+You can also set DataTable to use vitejs by default by registering `Builder::useVite()` inside the `AppServiceProvider`.
+
+```php
+namespace App\Providers;
+
+use Illuminate\Support\ServiceProvider;
+use Yajra\DataTables\Html\Builder;
+
+class AppServiceProvider extends ServiceProvider
+{
+ public function boot(): void
+ {
+ Builder::useVite();
+ }
+}
+```
+
+Upon registering, you can now use scripts and without the need to set the type to module.
+
+```php
+@push('scripts')
+ {{ $dataTable->scripts() }}
+@endpush
+```
+
+
## 05. Update the default app layout
From 04f0bc23547a86b6f72369297a6be18cb1ba36f8 Mon Sep 17 00:00:00 2001
From: Arjay Angeles
Date: Tue, 21 Mar 2023 09:43:33 +0800
Subject: [PATCH 3/7] docs: use latest version constraint
fix: https://github.com/yajra/laravel-datatables/issues/2969
---
installation.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/installation.md b/installation.md
index e24f5c0..992bbba 100644
--- a/installation.md
+++ b/installation.md
@@ -22,7 +22,7 @@ Laravel DataTables can be installed with [Composer](http://getcomposer.org/doc/0
Run the following command in your project to get the latest version of the package:
```bash
-composer require yajra/laravel-datatables-oracle:"^10.0"
+composer require yajra/laravel-datatables-oracle:"^10.3.1"
```
If you are using most of the DataTables plugins like Buttons & Html, you can alternatively use the all-in-one installer package.
From f2adb9ee84178c563fc6a8725d3483b2287b3ef7 Mon Sep 17 00:00:00 2001
From: Arjay Angeles
Date: Fri, 24 Mar 2023 11:39:31 +0800
Subject: [PATCH 4/7] docs: add actions property type
fix https://github.com/yajra/laravel-datatables/issues/2973
---
buttons-custom.md | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/buttons-custom.md b/buttons-custom.md
index 0f178ca..714faec 100644
--- a/buttons-custom.md
+++ b/buttons-custom.md
@@ -15,15 +15,17 @@ use Yajra\DataTables\Services\DataTable;
class UsersDataTable extends DataTable
{
- protected $actions = ['print', 'excel', 'myCustomAction'];
+ protected array $actions = ['print', 'excel', 'myCustomAction'];
public function html()
{
return $this->builder()
->columns($this->getColumns())
- ->parameters([
- 'dom' => 'Bfrtip',
- 'buttons' => ['print', 'excel', 'myCustomAction'],
+ ->dom('Bfrtip')
+ ->buttons([
+ 'print',
+ 'excel',
+ 'myCustomAction',
]);
}
From 6a1823d54132935fabd1af8ac0d0047e73ef246d Mon Sep 17 00:00:00 2001
From: Arjay Angeles
Date: Wed, 29 Mar 2023 13:10:57 +0800
Subject: [PATCH 5/7] docs: update generated service class
---
buttons-console.md | 155 ++++++++++++++-------------------------------
1 file changed, 46 insertions(+), 109 deletions(-)
diff --git a/buttons-console.md b/buttons-console.md
index 0efc0fc..478ffcc 100644
--- a/buttons-console.md
+++ b/buttons-console.md
@@ -23,72 +23,84 @@ This will create a `PostsDataTable` class in the `app\DataTables` directory.
```php
namespace App\DataTables;
-use App\User;
+use App\Models\Post;
+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 PostsDataTable extends DataTable
{
/**
- * Build DataTable class.
+ * Build the DataTable class.
*
- * @return \Yajra\DataTables\DataTableAbstract
+ * @param QueryBuilder $query Results from query() method.
*/
- public function dataTable()
+ public function dataTable(QueryBuilder $query): EloquentDataTable
{
- return $this->datatables
- ->eloquent($this->query())
- ->addColumn('action', 'path.to.action.view');
+ return (new EloquentDataTable($query))
+ ->addColumn('action', 'posts.action')
+ ->setRowId('id');
}
/**
- * Get the query object to be processed by dataTables.
- *
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
+ * Get the query source of dataTable.
*/
- public function query()
+ public function query(Post $model): QueryBuilder
{
- $query = User::query();
-
- return $this->applyScopes($query);
+ return $model->newQuery();
}
/**
- * Optional method if you want to use html builder.
- *
- * @return \Yajra\DataTables\Html\Builder
+ * Optional method if you want to use the html builder.
*/
- public function html()
+ public function html(): HtmlBuilder
{
return $this->builder()
+ ->setTableId('posts-table')
->columns($this->getColumns())
- ->ajax('')
- ->addAction(['width' => '80px'])
- ->parameters($this->getBuilderParameters());
+ ->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 columns.
- *
- * @return array
+ * Get the dataTable columns definition.
*/
- protected function getColumns()
+ public function getColumns(): array
{
return [
- 'id',
- // add your columns
- 'created_at',
- 'updated_at',
+ Column::computed('action')
+ ->exportable(false)
+ ->printable(false)
+ ->width(60)
+ ->addClass('text-center'),
+ Column::make('id'),
+ Column::make('add your columns'),
+ Column::make('created_at'),
+ Column::make('updated_at'),
];
}
/**
- * Get filename for export.
- *
- * @return string
+ * Get the filename for export.
*/
- protected function filename()
+ protected function filename(): string
{
- return 'posts_' . time();
+ return 'Posts_' . date('YmdHis');
}
}
```
@@ -104,81 +116,6 @@ php artisan datatables:make Posts --model
This will generate an `App\DataTables\PostsDataTable` class that uses `App\Post` as the base model for our query.
The exported filename will also be set to `posts_(timestamp)`.
-```php
-datatables
- ->eloquent($this->query())
- ->addColumn('action', 'path.to.action.view');
- }
-
- /**
- * Get the query object to be processed by dataTables.
- *
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
- */
- public function query()
- {
- $query = Post::query();
-
- return $this->applyScopes($query);
- }
-
- /**
- * Optional method if you want to use html builder.
- *
- * @return \Yajra\DataTables\Html\Builder
- */
- public function html()
- {
- return $this->builder()
- ->columns($this->getColumns())
- ->ajax('')
- ->addAction(['width' => '80px'])
- ->parameters($this->getBuilderParameters());
- }
-
- /**
- * Get columns.
- *
- * @return array
- */
- protected function getColumns()
- {
- return [
- 'id',
- // add your columns
- 'created_at',
- 'updated_at',
- ];
- }
-
- /**
- * Get filename for export.
- *
- * @return string
- */
- protected function filename()
- {
- return 'posts_' . time();
- }
-}
-```
-
### Model Namespace Option
From bd93c8d28bdfa2156ba0c5809e3b6f1838ed3453 Mon Sep 17 00:00:00 2001
From: Arjay Angeles
Date: Sat, 15 Apr 2023 08:32:10 +0800
Subject: [PATCH 6/7] chore: use English
---
html-builder-column-builder.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/html-builder-column-builder.md b/html-builder-column-builder.md
index d7df80a..1f1fd6e 100644
--- a/html-builder-column-builder.md
+++ b/html-builder-column-builder.md
@@ -30,7 +30,7 @@ $column = Column::make('id')
->title('Id')
->searchable(true)
->orderable(true)
- ->render('\'\' + (full[\'deleted_at\'] == null ? \'Attivo\' : \'Disattivo\') + \'
\';\'\'' )
+ ->render('\'\' + (full[\'deleted_at\'] == null ? \'Active\' : \'Inactive\') + \'
\';\'\'' )
->footer('Id')
->exportable(true)
->printable(true);
From 4241867c5c27fa5706a17c4ecfd48ba7fa878581 Mon Sep 17 00:00:00 2001
From: Arjay Angeles
Date: Wed, 10 May 2023 14:26:10 +0800
Subject: [PATCH 7/7] docs: controller to dataTable class
---
buttons-extended.md | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/buttons-extended.md b/buttons-extended.md
index 2811a86..3753c44 100644
--- a/buttons-extended.md
+++ b/buttons-extended.md
@@ -4,8 +4,8 @@ We can now extend and reuse our DataTable class inside our controller by using `
> IMPORTANT: Extended DataTable is only applicable on `^1.1` and above.
-
## Upgrading from v1.0 to v1.1
+
- Upgrade to `laravel-datatables-buttons:^1.1`
- Rename `ajax()` method to `dataTable()`
- Remove `->toJson()` from the method chain.
@@ -33,6 +33,7 @@ TO
```
## Quick Example:
+
```php
Route::get('datatable', function(RolesDataTable $dataTable){
return $dataTable->before(function (\Yajra\DataTables\DataTableAbstract $dataTable) {
@@ -54,3 +55,19 @@ Route::get('datatable', function(RolesDataTable $dataTable){
->render('path.to.view');
});
```
+
+## Passing data to DataTable class
+
+You can pass data from Controller to DataTable class using `with` api.
+
+```php
+Route::get('datatable', function(RolesDataTable $dataTable){
+ return $dataTable
+ ->with('key', 'value')
+ ->with([
+ 'key2' => 'value2',
+ 'key3' => 'value3',
+ ])
+ ->render('path.to.view');
+});
+```