From 3202d0327cc73399fce71b97dfaa1d34ed8acec8 Mon Sep 17 00:00:00 2001 From: Andy Tan Date: Mon, 20 Jan 2020 11:20:47 +0800 Subject: [PATCH 01/78] Replace make(true) with toJson --- response-object.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/response-object.md b/response-object.md index 84b13b5..6c1c088 100644 --- a/response-object.md +++ b/response-object.md @@ -1,6 +1,6 @@ # Object Response -To convert the response of DataTables to an object, just pass `true` on `make` api. +To convert the response of DataTables to an object, use `toJson` api. ```php use DataTables; From fcd6b31834dd6c7bc8dfad33276b06389b54bc1c Mon Sep 17 00:00:00 2001 From: skys215 Date: Sat, 22 Feb 2020 00:14:49 +0800 Subject: [PATCH 02/78] Update html-installation.md --- html-installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html-installation.md b/html-installation.md index e0d0415..a1e08f6 100644 --- a/html-installation.md +++ b/html-installation.md @@ -4,7 +4,7 @@ Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-html:^3.0` +`composer require yajra/laravel-datatables-html:^4.0` ## Configuration > This step is optional if you are using Laravel 5.5 From bac00f13d42bc5ea204f185f42d74382c1d13c06 Mon Sep 17 00:00:00 2001 From: skys215 Date: Sat, 22 Feb 2020 00:15:39 +0800 Subject: [PATCH 03/78] Update buttons-installation.md --- buttons-installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buttons-installation.md b/buttons-installation.md index 87e80a8..27ef960 100644 --- a/buttons-installation.md +++ b/buttons-installation.md @@ -2,7 +2,7 @@ Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-buttons:^3.0` +`composer require yajra/laravel-datatables-buttons:^4.0` ## Configuration > This step is optional if you are using Laravel 5.5 From dece4e9939bb71e714d5e26a683f380421932e08 Mon Sep 17 00:00:00 2001 From: "Md. Zahedul Hossain" Date: Thu, 19 Mar 2020 13:24:41 +0600 Subject: [PATCH 04/78] add note for addColumn api --- add-column.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/add-column.md b/add-column.md index 01dcaf3..92e82c0 100644 --- a/add-column.md +++ b/add-column.md @@ -2,6 +2,8 @@ You can add a custom column on your response by using `addColumn` api. +> {note} added columns are assumed to be computed columns and not part of the database. Thus, search/sort will be disabled on those columns. If you need them, use the `editColumn` api instead. + ## Add Column with Blade Syntax From 0ef23dd84ddde8e81ea309c8a0d49210fe09cef4 Mon Sep 17 00:00:00 2001 From: Oussama Date: Sun, 12 Apr 2020 00:04:51 +0200 Subject: [PATCH 05/78] Fix typo readbale => readable --- engine-query.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine-query.md b/engine-query.md index 4d2c09d..e800e53 100644 --- a/engine-query.md +++ b/engine-query.md @@ -1,7 +1,7 @@ # Query Builder Data Source You may use Laravel's Query Builder as data source for your dataTables. -You can look at `Yajra\DataTables\QueryDataTable` class which handles the conversion of your Query Builder into a readbale DataTable API response. +You can look at `Yajra\DataTables\QueryDataTable` class which handles the conversion of your Query Builder into a readable DataTable API response. ## Query Builder via Factory From adc481f7675d2c4d3438b7fec5c501bc18680475 Mon Sep 17 00:00:00 2001 From: 3s777 <3s777@rambler.ru> Date: Tue, 28 Apr 2020 10:35:34 +0300 Subject: [PATCH 06/78] Update relationships.md --- relationships.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/relationships.md b/relationships.md index ab91039..cccbd46 100644 --- a/relationships.md +++ b/relationships.md @@ -47,6 +47,10 @@ Looking at `{data: 'posts', name: 'posts.title'},`: - `data: posts` represents the data key (`data.posts`) that we are going to display on our table. - `name: posts.title` represents the `User` model relationship (`posts`) and the column we are going to perform our search (`title`). +It is advised that you include select('table.') on query to avoid weird issues where id from related model replaces the id of the main model. +```php +$posts = Post::with('user')->select('posts.*'); +``` ## Nested Relationships Same strategy goes for nested relationships but do **NOTE** that ordering is not yet fully tested on nested relationships. From 3b9e9f80edd65cfa24d67f3e2f6fc1dfd7eaead4 Mon Sep 17 00:00:00 2001 From: "Arjay Q. Angeles" Date: Fri, 8 May 2020 10:41:56 +0800 Subject: [PATCH 07/78] Fix https://github.com/yajra/laravel-datatables/issues/2387. --- installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation.md b/installation.md index 5cab060..8255b13 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:^9.0 +composer require yajra/laravel-datatables-oracle:"~9.0" ``` If you are using most of the DataTables plugins like Buttons & Html, you can alternatively use the all-in-one installer package. From 2a7d186e1b15acd3ae6240c533354ee8ba13ce9e Mon Sep 17 00:00:00 2001 From: Michael Newton Date: Tue, 6 Oct 2020 10:27:10 -0600 Subject: [PATCH 08/78] fix broken link in sidebar resolves yajra/laravel-datatables #2423 --- documentation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation.md b/documentation.md index cf92ae2..b577d8a 100644 --- a/documentation.md +++ b/documentation.md @@ -41,8 +41,8 @@ - [Remove Column](/docs/{{package}}/{{version}}/remove-column) - [Index Column](/docs/{{package}}/{{version}}/index-column) - [Raw Columns](/docs/{{package}}/{{version}}/raw-columns) - - [Export Columns](/docs/{{package}}/{{version}}/export-columns) - - [Print Columns](/docs/{{package}}/{{version}}/print-columns) + - [Export Columns](/docs/{{package}}/{{version}}/export-column) + - [Print Columns](/docs/{{package}}/{{version}}/print-column) - ## Row Editing - [Row Options](/docs/{{package}}/{{version}}/row-options) From 941dd740c0c1f57ff568e8ba23a0cdc02a666f96 Mon Sep 17 00:00:00 2001 From: Red Redimano Date: Wed, 7 Oct 2020 12:02:54 +0800 Subject: [PATCH 09/78] Add disable ordering sample code. --- order-column.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/order-column.md b/order-column.md index 0b78517..6413db8 100644 --- a/order-column.md +++ b/order-column.md @@ -31,4 +31,17 @@ Route::get('user-data', function () { $query->orderBy('status', $order); }); }); +``` + +Disable ordering via orderColumn. + +```php +use DataTables; + +Route::get('user-data', function () { + $model = App\User::query(); + + return DataTables::eloquent($model) + ->orderColumn('name', false); +}); ``` \ No newline at end of file From f60a0758ace316fd62914338ecc881431ec58e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20A=C5=9Fan?= Date: Fri, 20 Nov 2020 04:35:46 +0300 Subject: [PATCH 10/78] Typo corrected --- html-builder-table.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html-builder-table.md b/html-builder-table.md index 4069f36..285a6da 100644 --- a/html-builder-table.md +++ b/html-builder-table.md @@ -21,7 +21,7 @@ Route::get('users', function(Builder $builder) { ['data' => 'name', 'footer' => 'Name'], ['data' => 'email', 'footer' => 'Email'], ['data' => 'created_at', 'footer' => 'Created At'], - ['data' => 'updated_at', 'footer' => 'Updated At'), + ['data' => 'updated_at', 'footer' => 'Updated At'], ]); return view('users.index', compact('html')); From 399916ccc9c3400fb00b238edf7e511076f427ad Mon Sep 17 00:00:00 2001 From: fransiscusrolandamalau Date: Mon, 30 Nov 2020 08:08:29 +0700 Subject: [PATCH 11/78] Typo --- html-builder.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html-builder.md b/html-builder.md index f8204f0..7faf9c1 100644 --- a/html-builder.md +++ b/html-builder.md @@ -51,7 +51,7 @@ Route::get('users', function(Builder $builder) { ['data' => 'name', 'name' => 'name', 'title' => 'Name'], ['data' => 'email', 'name' => 'email', 'title' => 'Email'], ['data' => 'created_at', 'name' => 'created_at', 'title' => 'Created At'], - ['data' => 'updated_at', 'name' => 'updated_at', 'title' => 'Updated At']), + ['data' => 'updated_at', 'name' => 'updated_at', 'title' => 'Updated At'], ]); return view('users.index', compact('html')); From 9e19825d3bb8a0263dbdbd4fef59de38519bb151 Mon Sep 17 00:00:00 2001 From: "Arjay Q. Angeles" Date: Fri, 19 Mar 2021 18:09:43 +0800 Subject: [PATCH 12/78] Add Laravel Excel and FastExcel quick integration docs. --- buttons-fast-excel.md | 58 +++++++++++++++++++++++++++++++++++++++ buttons-laravel-excel.md | 59 ++++++++++++++++++++++++++++++++++++++++ documentation.md | 2 ++ 3 files changed, 119 insertions(+) create mode 100644 buttons-fast-excel.md create mode 100644 buttons-laravel-excel.md diff --git a/buttons-fast-excel.md b/buttons-fast-excel.md new file mode 100644 index 0000000..809ba75 --- /dev/null +++ b/buttons-fast-excel.md @@ -0,0 +1,58 @@ +# Fast Excel Integration + +[Fast-Excel](https://github.com/rap2hpoutre/fast-excel) is recommended when exporting bulk records. + +## Usage + +1. Install `fast-excel` using `composer require rap2hpoutre/fast-excel`. +2. Create a dataTable class `php artisan datatables:make Users` +3. Adjust `UsersDataTable` as needed. +4. Set property `$fastExcel = true`. + +```php +class UsersDataTable extends DataTable +{ + protected $fastExcel = true; + + ... +} +``` + +5. DataTables will now export csv & excel using `fast-excel` package. + + +## Faster export by disabling the fast-excel callback + +1. Just set property `$fastExcelCallback = false`. This is enabled by default for a better formatted output of exported file. + +```php +class UsersDataTable extends DataTable +{ + protected $fastExcel = true; + protected $fastExcelCallback = false; + +``` + +2. Exported file will now be based on how your query was structured. No header formatting and all selected columns in sql will be included in the output. + +## Using custom callback + +Just override the `fastExcelCallback` method: + +```php +class UsersDataTable extends DataTable +{ + protected $fastExcel = true; + + public function fastExcelCallback() + { + return function ($row) { + return [ + 'Name' => $row['name'], + 'Email' => $row['email'], + ]; + }; + } + +... +``` \ No newline at end of file diff --git a/buttons-laravel-excel.md b/buttons-laravel-excel.md new file mode 100644 index 0000000..3756cb3 --- /dev/null +++ b/buttons-laravel-excel.md @@ -0,0 +1,59 @@ +# Laravel Excel Integration + +[Laravel Excel](https://github.com/Maatwebsite/Laravel-Excel) is the default package used when exporting DataTables to Excel and CSV. + +## Using Export Class + +1. Create an export class `php artisan make:export UsersExport` +2. Update the generated export class and extend `DataTablesCollectionExport` + +```php +namespace App\Exports; + +use Yajra\DataTables\Exports\DataTablesCollectionExport; + +class UsersExport extends DataTablesCollectionExport +{ + +} +``` + +3. Update your `UsersDataTable` class and set `protected $exportClass = UsersExport::class` + +```php +class UsersDataTable extends DataTable +{ + protected $exportClass = UsersExport::class; + +``` + +4. Update your export class as needed. See official package docs: https://docs.laravel-excel.com/3.1/exports/collection.html + +## Example Export Class + +```php +namespace App\Exports; + +use Maatwebsite\Excel\Concerns\WithMapping; +use Yajra\DataTables\Exports\DataTablesCollectionExport; + +class UsersExport extends DataTablesCollectionExport implements WithMapping +{ + public function headings(): array + { + return [ + 'Name', + 'Email', + ]; + } + + public function map($row): array + { + return [ + $row['name'], + $row['email'], + ]; + } +} +``` + diff --git a/documentation.md b/documentation.md index b577d8a..c8ca946 100644 --- a/documentation.md +++ b/documentation.md @@ -103,6 +103,8 @@ - [Sending Parameters](/docs/{{package}}/{{version}}/buttons-with) - [Extended DataTable](/docs/{{package}}/{{version}}/buttons-extended) - [Buttons Command](/docs/{{package}}/{{version}}/buttons-console) + - [Laravel Excel Export](/docs/{{package}}/{{version}}/buttons-laravel-excel) + - [Fast Excel Export](/docs/{{package}}/{{version}}/buttons-fast-excel) - [Github](https://github.com/yajra/laravel-datatables-buttons) - ## Editor From c87047bfaebc687f7ea0ff7b371778653da9d46b Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 30 Sep 2021 08:51:21 +0800 Subject: [PATCH 13/78] Add notes for the limitations. --- buttons-fast-excel.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/buttons-fast-excel.md b/buttons-fast-excel.md index 809ba75..d610c4b 100644 --- a/buttons-fast-excel.md +++ b/buttons-fast-excel.md @@ -1,6 +1,10 @@ # Fast Excel Integration -[Fast-Excel](https://github.com/rap2hpoutre/fast-excel) is recommended when exporting bulk records. +[Fast-Excel](https://github.com/rap2hpoutre/fast-excel) is recommended when exporting bulk records. + +## LIMITATIONS! + +FastExcel integration uses cursor behind the scene thus eager loaded columns will not work on export. You must used join statements if you want to export related columns. Also, column value formatting like converting boolean to Yes or No should be done on SQL LEVEL. ## Usage From 2e7080f69c69b56aff0cda1059762ea5c123eb96 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 30 Sep 2021 08:57:13 +0800 Subject: [PATCH 14/78] Fix typo. --- buttons-fast-excel.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buttons-fast-excel.md b/buttons-fast-excel.md index d610c4b..fa04177 100644 --- a/buttons-fast-excel.md +++ b/buttons-fast-excel.md @@ -4,7 +4,7 @@ ## LIMITATIONS! -FastExcel integration uses cursor behind the scene thus eager loaded columns will not work on export. You must used join statements if you want to export related columns. Also, column value formatting like converting boolean to Yes or No should be done on SQL LEVEL. +FastExcel integration uses cursor behind the scene thus eager loaded columns will not work on export. You MUST use join statements if you want to export related columns. Also, column value formatting like converting boolean to Yes or No should be done on SQL LEVEL. ## Usage From 379060c29bd19f5b74022f2acd783612f922ad31 Mon Sep 17 00:00:00 2001 From: schonhoff <42345405+schonhoff@users.noreply.github.com> Date: Sat, 26 Mar 2022 23:31:45 +0100 Subject: [PATCH 15/78] Added setRowId description Added the setRowId documentation mentioned in https://github.com/yajra/laravel-datatables/issues/2661#issuecomment-883857714 --- index-column.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/index-column.md b/index-column.md index a962ef9..0afb93a 100644 --- a/index-column.md +++ b/index-column.md @@ -16,4 +16,20 @@ Route::get('user-data', function() { ``` Using `addIndexColumn` will add another column on your response with a column name that is set on [`index_column`](/docs/{{package}}/{{version}}/general-settings#index-column) configuration. -The default index column name is `DT_RowIndex` +The default index column name is `DT_RowIndex`. + +If you want to customize the index used by the `DT_RowIndex`, you can use `setRowId('COLUMN')` to change the index number. + +```php +use DataTables; + +Route::get('user-data', function() { + $model = App\User::query(); + + return DataTables::eloquent($model) + ->setRowId('id') + ->toJson(); +}); +``` + +Be careful with this option, an index should be unique and an integer to be useful for DataTables. From cd867fbc24d7e7c8786e83b5b751f7498c9fdeee Mon Sep 17 00:00:00 2001 From: Arne Perschke Date: Thu, 7 Jul 2022 10:58:16 +0200 Subject: [PATCH 16/78] Added SearchPanes documentation --- documentation.md | 5 ++ quick-starter.md | 8 ++- search-panes-hide-columns.md | 14 +++++ search-panes-options.md | 30 ++++++++++ search-panes-starter.md | 112 +++++++++++++++++++++++++++++++++++ 5 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 search-panes-hide-columns.md create mode 100644 search-panes-options.md create mode 100644 search-panes-starter.md diff --git a/documentation.md b/documentation.md index c8ca946..9e57f17 100644 --- a/documentation.md +++ b/documentation.md @@ -65,6 +65,11 @@ - [Order Columns](/docs/{{package}}/{{version}}/order-columns) - [Order By Nulls Last](/docs/{{package}}/{{version}}/order-by-nulls-last) +- ## SearchPanes + - [Add SearchPanes](/docs/{{package}}/{{version}}/search-panes-starter.md) + - [Hide Columns in SearchPanes](/docs/{{package}}/{{version}}/search-panes-hide-columns.md) + - [Further options](/docs/{{package}}/{{version}}/search-panes-options.md) + - ## Utilities - [XSS filtering](/docs/{{package}}/{{version}}/xss) - [Blacklist Columns](/docs/{{package}}/{{version}}/blacklist) diff --git a/quick-starter.md b/quick-starter.md index 6d152b0..57c976b 100644 --- a/quick-starter.md +++ b/quick-starter.md @@ -31,9 +31,11 @@ php artisan ui bootstrap --auth ## Install Datatables.net assets ``` -yarn add datatables.net-bs4 datatables.net-buttons-bs4 +yarn add datatables.net-bs4 datatables.net-buttons-bs4 datatables.net-select-bs4 datatables.net-searchpanes-bs4 ``` +> {tip} datatables.net-select-bs4` and `datatables.net-searchpanes-bs4` are only required if you want to use SearchPanes + ## Register datatables.net assets in bootstrap.js and app.scss Edit `resources/js/bootstrap.js` and add the following: @@ -41,12 +43,16 @@ Edit `resources/js/bootstrap.js` and add the following: require('bootstrap'); require('datatables.net-bs4'); require('datatables.net-buttons-bs4'); + require('datatables.net-select-bs4'); + require('datatables.net-searchpanes-bs4'); Edit `resources/scss/app.scss` and add the following: // DataTables @import "~datatables.net-bs4/css/dataTables.bootstrap4.css"; @import "~datatables.net-buttons-bs4/css/buttons.bootstrap4.css"; + @import '~datatables.net-select-bs4/css/select.dataTables.css'; + @import '~datatables.net-searchpanes-dt/css/searchPanes.dataTables.css'; ## Compile assets diff --git a/search-panes-hide-columns.md b/search-panes-hide-columns.md new file mode 100644 index 0000000..3064861 --- /dev/null +++ b/search-panes-hide-columns.md @@ -0,0 +1,14 @@ +# Hide Columns in SearchPanes + +Some columns you might not want in your SearchPanes, to hide them you can add `->searchPanes(false)` in your column +definition: + +```php +protected function getColumns() : array +{ + return [ + Column::make('id') + ->searchPanes(false); + ] +} +``` \ No newline at end of file diff --git a/search-panes-options.md b/search-panes-options.md new file mode 100644 index 0000000..4026db4 --- /dev/null +++ b/search-panes-options.md @@ -0,0 +1,30 @@ +# Further SearchPanes options + +```php +public function html() : \Yajra\DataTables\Html\Builder +{ + return $this->builder() + ->searchPanes( + SearchPane::make() + ->hideCount() // Hides the count next to the options, the amount of records with the filters + ->hideTotal() // Hides the total how many are available without the filters + ->clear(false) // Hides the clear button, used to clear the user selection + ->controls(false) // disable controls (search for filters) + ->layout('columns-2') // can be used to set the layout (amount of search panes in one row) + ->order(['user_id', 'age']) // Sets the order of the search panes, uses the name of the search pane + ->orderable(false) // If the order icons should be displayed in the interface + ->panes( // Can be used to add additional search panes which do not belong to any existing column + [ + // SearchPane::make()... + ] + ) + ->dtOpts( // Sets the options for the datatables inside the searchpanes + [ + 'paging' => true, + 'pagingType' => 'numbers' + ] + ) + + ); +} +``` diff --git a/search-panes-starter.md b/search-panes-starter.md new file mode 100644 index 0000000..a9c96e9 --- /dev/null +++ b/search-panes-starter.md @@ -0,0 +1,112 @@ +# Add SearchPane + +[SearchPanes](https://datatables.net/extensions/searchpanes/) ([example](https://datatables.net/extensions/searchpanes/examples/initialisation/simple.html)) +allow the user to quickly filter the datatable after predefined filters. + +> {note} To use datatables you need to make sure that the npm packages `datatables.net-select-bs4` and `datatables.net-searchpanes-bs4` are installed and added to your `app.js`/`app.css` files. + +## Adding SearchPanes to the frontend + +To be able to see SearchPanes you need to either add them fixed in the dom (displayed at all time) or add a button which +opens them as popup. + +### Adding SearchPanes fixed in the dom + +SearchPanes can be added to a table via the dom string, in it, they are marked with a `P` if you for example +are using `Bfrtip` as dom you can use `PBfrtip` to display the SearchPanes at the top of the datatable, or `BfrtipP` +to display them at the very bottom. + +Setting the dom String with the `\Yajra\DataTables\Html\Builder`: +```php +public function html() : \Yajra\DataTables\Html\Builder +{ + // Setting the dom string directly + return $this->builder() + ->searchPanes(SearchPane::make()) + ->dom('PBfrtip'); + + // Alternatively set the dom with parameters + return $this->builder() + ->searchPanes(SearchPane::make()) + ->parameters([ + 'dom' => 'PBfrtip' + ]); +} +``` + +### Adding SearchPanes with a button + +To add a button which opens the SearchPanes you need to make one extending `searchPanes`: + +```php +public function html() : \Yajra\DataTables\Html\Builder +{ + // Adding via class + return $this->builder() + ->searchPanes(SearchPane::make()) + ->buttons([ + \Yajra\DataTables\Html\Button::make('searchPanes') + // other buttons... + ]); + + // Alternatively set the buttons with options + return $this->builder() + ->searchPanes(SearchPane::make()) + ->parameters([ + 'buttons' => ['searchPanes', /*other buttons...*/] + ]); +} +``` + +## Adding SearchPanes to the backend + +The SearchPanes can be filled in the datatables declaration via the `searchPane()` method. The method takes the column +for which the SearchPane is, as well as the options of the SearchPane. It also allows you to set custom processing for +the options. + + +```php +public function dataTable($query) : Yajra\DataTables\DataTableAbstract +{ + return datatables() + ->eloquent($query) + // Adding the SearchPane + ->searchPane( + /* + * This is the column for which this SearchPane definition is for + */ + 'user_id', + + /* + * Here we define the options for our SearchPane. This should be either a collection or an array with the + * form: + * [ + * [ + * 'value' => 1, + * 'label' => 'display value', + * 'total' => 5, // optional + * 'count' => 3 // optional + * ], + * [ + * 'value' => 2, + * 'label' => 'display value 2', + * 'total' => 6, // optional + * 'count' => 5 // optional + * ], + * ] + */ + fn() => User::query()->select('id as value', 'name as label')->get(), + + /* + * This is the filter that gets executed when the user selects one or more values on the SearchPane. The + * values are always given in an array even if just one is selected + */ + function (\Illuminate\Database\Eloquent\Builder $query, array $values) { + return $query + ->whereIn( + 'id', + $values); + } + ); +} +``` From 13c637127c8ca6800dadf1ba02dd3e8a9b5367d4 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 13:46:35 +0800 Subject: [PATCH 17/78] Fix link --- documentation.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation.md b/documentation.md index 9e57f17..be4d6d7 100644 --- a/documentation.md +++ b/documentation.md @@ -66,9 +66,9 @@ - [Order By Nulls Last](/docs/{{package}}/{{version}}/order-by-nulls-last) - ## SearchPanes - - [Add SearchPanes](/docs/{{package}}/{{version}}/search-panes-starter.md) - - [Hide Columns in SearchPanes](/docs/{{package}}/{{version}}/search-panes-hide-columns.md) - - [Further options](/docs/{{package}}/{{version}}/search-panes-options.md) + - [Add SearchPanes](/docs/{{package}}/{{version}}/search-panes-starter) + - [Hide Columns in SearchPanes](/docs/{{package}}/{{version}}/search-panes-hide-columns) + - [Further options](/docs/{{package}}/{{version}}/search-panes-options) - ## Utilities - [XSS filtering](/docs/{{package}}/{{version}}/xss) From 7e7a09c16e93712ab4ccb37148561aba581920ba Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:14:02 +0800 Subject: [PATCH 18/78] Bump version to L9 --- installation.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installation.md b/installation.md index 8255b13..2db07f1 100644 --- a/installation.md +++ b/installation.md @@ -11,7 +11,7 @@ ### Requirements -- [Laravel 5.5+](https://github.com/laravel/framework) +- [Laravel 9+](https://github.com/laravel/framework) - [jQuery DataTables v1.10.x](http://datatables.net/) @@ -22,13 +22,13 @@ 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:"~9.0" +composer require yajra/laravel-datatables-oracle:"^10.0" ``` If you are using most of the DataTables plugins like Buttons & Html, you can alternatively use the all-in-one installer package. ```bash -composer require yajra/laravel-datatables:^1.5 +composer require yajra/laravel-datatables:^9.0 ``` From 195e19a71da2b50914304f279759a8769f9deab3 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:21:48 +0800 Subject: [PATCH 19/78] Add deprecation notes --- skip-total-records.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/skip-total-records.md b/skip-total-records.md index aa00a6b..0400387 100644 --- a/skip-total-records.md +++ b/skip-total-records.md @@ -1,5 +1,7 @@ # Skip Total Records +> Note: This is deprecated on v10. Just use setTotalRecords instead. + Skip total records aims to improve dataTables response time by skipping the total records count query and settings its value equals to the filtered total records. From c47b26387b985c276045497181b741df269bf894 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:25:22 +0800 Subject: [PATCH 20/78] Bump to v9 --- buttons-installation.md | 2 +- html-installation.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buttons-installation.md b/buttons-installation.md index 27ef960..9deaf74 100644 --- a/buttons-installation.md +++ b/buttons-installation.md @@ -2,7 +2,7 @@ Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-buttons:^4.0` +`composer require yajra/laravel-datatables-buttons:^9.0` ## Configuration > This step is optional if you are using Laravel 5.5 diff --git a/html-installation.md b/html-installation.md index a1e08f6..a4f7a1d 100644 --- a/html-installation.md +++ b/html-installation.md @@ -4,7 +4,7 @@ Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-html:^4.0` +`composer require yajra/laravel-datatables-html:^9.0` ## Configuration > This step is optional if you are using Laravel 5.5 From a41c7ba7313a518641083dae8fef6b69945cd28a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:28:06 +0800 Subject: [PATCH 21/78] Add fractal plugin section --- documentation.md | 77 +++++++++++++++++++++-------------------- fractal-installation.md | 24 +++++++++++++ 2 files changed, 64 insertions(+), 37 deletions(-) create mode 100644 fractal-installation.md diff --git a/documentation.md b/documentation.md index be4d6d7..74bce65 100644 --- a/documentation.md +++ b/documentation.md @@ -28,8 +28,6 @@ - ## Response - [Array Response](/docs/{{package}}/{{version}}/response-array) - [Object Response](/docs/{{package}}/{{version}}/response-object) - - [Fractal Transformer](/docs/{{package}}/{{version}}/response-fractal) - - [Fractal Serializer](/docs/{{package}}/{{version}}/response-fractal-serializer) - [Additional Data Response](/docs/{{package}}/{{version}}/response-with) - [Only Columns](/docs/{{package}}/{{version}}/response-only) - [Response Resource](/docs/{{package}}/{{version}}/response-resource) @@ -82,42 +80,47 @@ ### PLUGINS - ## HTML Builder - - [Installation](/docs/{{package}}/{{version}}/html-installation) - - [Builder](/docs/{{package}}/{{version}}/html-builder) - - [Table](/docs/{{package}}/{{version}}/html-builder-table) - - [Config](/docs/{{package}}/{{version}}/html-builder-config) - - [Columns](/docs/{{package}}/{{version}}/html-builder-column) - - [Column Builder](/docs/{{package}}/{{version}}/html-builder-column-builder) - - [Macro](/docs/{{package}}/{{version}}/html-builder-macro) - - [Ajax](/docs/{{package}}/{{version}}/html-builder-ajax) - - [Minified Ajax](/docs/{{package}}/{{version}}/html-builder-minified-ajax) - - [Post Ajax](/docs/{{package}}/{{version}}/html-builder-post-ajax) - - [Parameters](/docs/{{package}}/{{version}}/html-builder-parameters) - - [Events/Callbacks](/docs/{{package}}/{{version}}/html-builder-callbacks) - - [Add Action](/docs/{{package}}/{{version}}/html-builder-action) - - [Add Checkbox](/docs/{{package}}/{{version}}/html-builder-checkbox) - - [Add Index](/docs/{{package}}/{{version}}/html-builder-index) - - [Github](https://github.com/yajra/laravel-datatables-html) + - [Installation](/docs/{{package}}/{{version}}/html-installation) + - [Builder](/docs/{{package}}/{{version}}/html-builder) + - [Table](/docs/{{package}}/{{version}}/html-builder-table) + - [Config](/docs/{{package}}/{{version}}/html-builder-config) + - [Columns](/docs/{{package}}/{{version}}/html-builder-column) + - [Column Builder](/docs/{{package}}/{{version}}/html-builder-column-builder) + - [Macro](/docs/{{package}}/{{version}}/html-builder-macro) + - [Ajax](/docs/{{package}}/{{version}}/html-builder-ajax) + - [Minified Ajax](/docs/{{package}}/{{version}}/html-builder-minified-ajax) + - [Post Ajax](/docs/{{package}}/{{version}}/html-builder-post-ajax) + - [Parameters](/docs/{{package}}/{{version}}/html-builder-parameters) + - [Events/Callbacks](/docs/{{package}}/{{version}}/html-builder-callbacks) + - [Add Action](/docs/{{package}}/{{version}}/html-builder-action) + - [Add Checkbox](/docs/{{package}}/{{version}}/html-builder-checkbox) + - [Add Index](/docs/{{package}}/{{version}}/html-builder-index) + - [Github](https://github.com/yajra/laravel-datatables-html) - ## Buttons - - [Installation](/docs/{{package}}/{{version}}/buttons-installation) - - [Configuration](/docs/{{package}}/{{version}}/buttons-config) - - [Quick Starter](/docs/{{package}}/{{version}}/buttons-starter) - - [DataTable Buttons](/docs/{{package}}/{{version}}/buttons-export) - - [Custom Actions](/docs/{{package}}/{{version}}/buttons-custom) - - [Sending Parameters](/docs/{{package}}/{{version}}/buttons-with) - - [Extended DataTable](/docs/{{package}}/{{version}}/buttons-extended) - - [Buttons Command](/docs/{{package}}/{{version}}/buttons-console) - - [Laravel Excel Export](/docs/{{package}}/{{version}}/buttons-laravel-excel) - - [Fast Excel Export](/docs/{{package}}/{{version}}/buttons-fast-excel) - - [Github](https://github.com/yajra/laravel-datatables-buttons) + - [Installation](/docs/{{package}}/{{version}}/buttons-installation) + - [Configuration](/docs/{{package}}/{{version}}/buttons-config) + - [Quick Starter](/docs/{{package}}/{{version}}/buttons-starter) + - [DataTable Buttons](/docs/{{package}}/{{version}}/buttons-export) + - [Custom Actions](/docs/{{package}}/{{version}}/buttons-custom) + - [Sending Parameters](/docs/{{package}}/{{version}}/buttons-with) + - [Extended DataTable](/docs/{{package}}/{{version}}/buttons-extended) + - [Buttons Command](/docs/{{package}}/{{version}}/buttons-console) + - [Laravel Excel Export](/docs/{{package}}/{{version}}/buttons-laravel-excel) + - [Fast Excel Export](/docs/{{package}}/{{version}}/buttons-fast-excel) + - [Github](https://github.com/yajra/laravel-datatables-buttons) + +- ## Fractal + - [Installation](/docs/{{package}}/{{version}}/fractal-installation) + - [Fractal Transformer](/docs/{{package}}/{{version}}/response-fractal) + - [Fractal Serializer](/docs/{{package}}/{{version}}/response-fractal-serializer) - ## Editor - - [Installation](/docs/{{package}}/{{version}}/editor-installation) - - [Editor Command](/docs/{{package}}/{{version}}/editor-command) - - [Editor Model](/docs/{{package}}/{{version}}/editor-model) - - [Editor Rules](/docs/{{package}}/{{version}}/editor-rules) - - [Event Hooks](/docs/{{package}}/{{version}}/editor-events) - - [Usage](/docs/{{package}}/{{version}}/editor-usage) - - [Tutorial](/docs/{{package}}/{{version}}/editor-tutorial) - - [Github](https://github.com/yajra/laravel-datatables-editor) + - [Installation](/docs/{{package}}/{{version}}/editor-installation) + - [Editor Command](/docs/{{package}}/{{version}}/editor-command) + - [Editor Model](/docs/{{package}}/{{version}}/editor-model) + - [Editor Rules](/docs/{{package}}/{{version}}/editor-rules) + - [Event Hooks](/docs/{{package}}/{{version}}/editor-events) + - [Usage](/docs/{{package}}/{{version}}/editor-usage) + - [Tutorial](/docs/{{package}}/{{version}}/editor-tutorial) + - [Github](https://github.com/yajra/laravel-datatables-editor) diff --git a/fractal-installation.md b/fractal-installation.md new file mode 100644 index 0000000..c61a3e2 --- /dev/null +++ b/fractal-installation.md @@ -0,0 +1,24 @@ +# Fractal Plugin Installation + +Run the following command in your project to get the latest version of the plugin: + +`composer require yajra/laravel-datatables-fractal:^9.0` + +## Configuration +> This step is optional if you are using Laravel 5.5 + +Open the file ```config/app.php``` and then add following service provider. + +```php +'providers' => [ + // ... + Yajra\DataTables\DataTablesServiceProvider::class, + Yajra\DataTables\FractalServiceProvider::class, +], +``` + +After completing the step above, use the following command to publish configuration & assets: + +``` +php artisan vendor:publish --tag=datatables-buttons +``` From 7dd6959a78152cfd1117cb53983755ee45406a3a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:29:53 +0800 Subject: [PATCH 22/78] Fix publish cmd --- fractal-installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fractal-installation.md b/fractal-installation.md index c61a3e2..16bfdb4 100644 --- a/fractal-installation.md +++ b/fractal-installation.md @@ -20,5 +20,5 @@ Open the file ```config/app.php``` and then add following service provider. After completing the step above, use the following command to publish configuration & assets: ``` -php artisan vendor:publish --tag=datatables-buttons +php artisan vendor:publish --tag=datatables-fractal --force ``` From 5f3347e3da9eca2a58eb1544ccdf9f41d9d5a473 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:40:05 +0800 Subject: [PATCH 23/78] Add section for export plugin --- documentation.md | 3 +++ exports-installation.md | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 exports-installation.md diff --git a/documentation.md b/documentation.md index 74bce65..d284b48 100644 --- a/documentation.md +++ b/documentation.md @@ -115,6 +115,9 @@ - [Fractal Transformer](/docs/{{package}}/{{version}}/response-fractal) - [Fractal Serializer](/docs/{{package}}/{{version}}/response-fractal-serializer) +- ## Livewire + Batch Job Exports + - [Installation](/docs/{{package}}/{{version}}/exports-installation) + - ## Editor - [Installation](/docs/{{package}}/{{version}}/editor-installation) - [Editor Command](/docs/{{package}}/{{version}}/editor-command) diff --git a/exports-installation.md b/exports-installation.md new file mode 100644 index 0000000..3788d3a --- /dev/null +++ b/exports-installation.md @@ -0,0 +1,27 @@ +# Export Plugin Installation + +Github: https://github.com/yajra/laravel-datatables-export + +Run the following command in your project to get the latest version of the plugin: + +`composer require yajra/laravel-datatables-export:^0.12` + +## Configuration + +> This step is optional if you are using Laravel 5.5 + +Open the file ```config/app.php``` and then add following service provider. + +```php +'providers' => [ + // ... + Yajra\DataTables\DataTablesServiceProvider::class, + Yajra\DataTables\ExportServiceProvider::class, +], +``` + +After completing the step above, use the following command to publish configuration & assets: + +``` +php artisan vendor:publish --tag=datatables-export --force +``` From eed782b0d2b98fa71ce526ddbc5585c035090668 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:40:05 +0800 Subject: [PATCH 24/78] Add section for export plugin --- buttons-installation.md | 2 ++ fractal-installation.md | 2 ++ html-installation.md | 3 +++ 3 files changed, 7 insertions(+) diff --git a/buttons-installation.md b/buttons-installation.md index 9deaf74..424966c 100644 --- a/buttons-installation.md +++ b/buttons-installation.md @@ -1,5 +1,7 @@ # Buttons Plugin Installation +Github: https://github.com/yajra/laravel-datatables-buttons + Run the following command in your project to get the latest version of the plugin: `composer require yajra/laravel-datatables-buttons:^9.0` diff --git a/fractal-installation.md b/fractal-installation.md index 16bfdb4..e210f6b 100644 --- a/fractal-installation.md +++ b/fractal-installation.md @@ -1,5 +1,7 @@ # Fractal Plugin Installation +Github: https://github.com/yajra/laravel-datatables-fractal + Run the following command in your project to get the latest version of the plugin: `composer require yajra/laravel-datatables-fractal:^9.0` diff --git a/html-installation.md b/html-installation.md index a4f7a1d..507ce61 100644 --- a/html-installation.md +++ b/html-installation.md @@ -2,11 +2,14 @@ ## Installation +Github: https://github.com/yajra/laravel-datatables-html + Run the following command in your project to get the latest version of the plugin: `composer require yajra/laravel-datatables-html:^9.0` ## Configuration + > This step is optional if you are using Laravel 5.5 Open the file ```config/app.php``` and then add following service provider. From 83f08d688e6006c077cf23d416586d8a08caee11 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:43:39 +0800 Subject: [PATCH 25/78] Use docs from repo --- documentation.md | 2 +- exports-installation.md | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/documentation.md b/documentation.md index d284b48..4d760f9 100644 --- a/documentation.md +++ b/documentation.md @@ -115,7 +115,7 @@ - [Fractal Transformer](/docs/{{package}}/{{version}}/response-fractal) - [Fractal Serializer](/docs/{{package}}/{{version}}/response-fractal-serializer) -- ## Livewire + Batch Job Exports +- ## Export - [Installation](/docs/{{package}}/{{version}}/exports-installation) - ## Editor diff --git a/exports-installation.md b/exports-installation.md index 3788d3a..79dd9fa 100644 --- a/exports-installation.md +++ b/exports-installation.md @@ -2,26 +2,29 @@ Github: https://github.com/yajra/laravel-datatables-export -Run the following command in your project to get the latest version of the plugin: +This package is a plugin of Laravel DataTables for handling server-side exporting using Queue, OpenSpout and Livewire. -`composer require yajra/laravel-datatables-export:^0.12` +## Quick Installation -## Configuration - -> This step is optional if you are using Laravel 5.5 +``` +composer require yajra/laravel-datatables-export -W +``` -Open the file ```config/app.php``` and then add following service provider. +The package also requires batch job: -```php -'providers' => [ - // ... - Yajra\DataTables\DataTablesServiceProvider::class, - Yajra\DataTables\ExportServiceProvider::class, -], +``` +php artisan queue:batches-table +php artisan migrate ``` -After completing the step above, use the following command to publish configuration & assets: +## Service Provider (Optional since Laravel 5.5+) ``` -php artisan vendor:publish --tag=datatables-export --force +Yajra\DataTables\ExportServiceProvider::class +``` + +## Configuration and Assets (Optional) + ``` +$ php artisan vendor:publish --tag=datatables-export --force +``` \ No newline at end of file From e80661f9c755944c5374fcb0621f18d96403165d Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:47:28 +0800 Subject: [PATCH 26/78] Add more export docs --- exports-usage.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 exports-usage.md diff --git a/exports-usage.md b/exports-usage.md new file mode 100644 index 0000000..f5d6a29 --- /dev/null +++ b/exports-usage.md @@ -0,0 +1,24 @@ +# Export Usage + +## Usage + +1. Add the export-button livewire component on your view file that uses dataTable class. + +```php + +``` + +2. On your `DataTable` class, use `WithExportQueue` + +```php +use Yajra\DataTables\WithExportQueue; + +class PermissionsDataTable extends DataTable +{ + use WithExportQueue; + + ... +} +``` + +3. Run your queue worker. Ex: `php artisan queue:work` From e65838bb600fa1493e44920aa632880965942bc7 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:47:28 +0800 Subject: [PATCH 27/78] Add more export docs --- documentation.md | 3 ++ exports-options.md | 98 ++++++++++++++++++++++++++++++++++++++++++++++ exports-purge.md | 20 ++++++++++ 3 files changed, 121 insertions(+) create mode 100644 exports-options.md create mode 100644 exports-purge.md diff --git a/documentation.md b/documentation.md index 4d760f9..9a7b5e9 100644 --- a/documentation.md +++ b/documentation.md @@ -117,6 +117,9 @@ - ## Export - [Installation](/docs/{{package}}/{{version}}/exports-installation) + - [Usage](/docs/{{package}}/{{version}}/exports-usage) + - [Purge](/docs/{{package}}/{{version}}/exports-purge) + - [Options](/docs/{{package}}/{{version}}/exports-options) - ## Editor - [Installation](/docs/{{package}}/{{version}}/editor-installation) diff --git a/exports-options.md b/exports-options.md new file mode 100644 index 0000000..895d397 --- /dev/null +++ b/exports-options.md @@ -0,0 +1,98 @@ +# Export Options + +## Export Type + +You can set the export type by setting the property to `csv` or `xlsx`. Default value is `xlsx`. + +```php + + +``` + +## Set Excel Sheet Name + +Option 1: You can set the Excel sheet name by setting the property. + +```php + +``` + +Option 2: You can also set the Excel sheet name by overwriting the method. + +```php +protected function sheetName() : string +{ + return "Yearly Report"; +} +``` + +## Formatting Columns + +You can format the column by setting it via Column definition on you DataTable service class. + +```php +Column::make('mobile')->exportFormat('00000000000'), +``` + +The format above will treat mobile numbers as text with leading zeroes. + +## Numeric Fields Formatting + +The package will auto-detect numeric fields and can be used with custom formats. + +```php +Column::make('total')->exportFormat('0.00'), +Column::make('count')->exportFormat('#,##0'), +Column::make('average')->exportFormat('#,##0.00'), +``` + +## Date Fields Formatting + +The package will auto-detect date fields when used with a valid format or is a DateTime instance. + +```php +Column::make('report_date')->exportFormat('mm/dd/yyyy'), +Column::make('created_at'), +Column::make('updated_at')->exportFormat(NumberFormat::FORMAT_DATE_DATETIME), +``` + +## Valid Date Formats + +Valid date formats can be adjusted on `datatables-export.php` config file. + +```php + 'date_formats' => [ + 'mm/dd/yyyy', + NumberFormat::FORMAT_DATE_DATETIME, + NumberFormat::FORMAT_DATE_YYYYMMDD, + NumberFormat::FORMAT_DATE_XLSX22, + NumberFormat::FORMAT_DATE_DDMMYYYY, + NumberFormat::FORMAT_DATE_DMMINUS, + NumberFormat::FORMAT_DATE_DMYMINUS, + NumberFormat::FORMAT_DATE_DMYSLASH, + NumberFormat::FORMAT_DATE_MYMINUS, + NumberFormat::FORMAT_DATE_TIME1, + NumberFormat::FORMAT_DATE_TIME2, + NumberFormat::FORMAT_DATE_TIME3, + NumberFormat::FORMAT_DATE_TIME4, + NumberFormat::FORMAT_DATE_TIME5, + NumberFormat::FORMAT_DATE_TIME6, + NumberFormat::FORMAT_DATE_TIME7, + NumberFormat::FORMAT_DATE_XLSX14, + NumberFormat::FORMAT_DATE_XLSX15, + NumberFormat::FORMAT_DATE_XLSX16, + NumberFormat::FORMAT_DATE_XLSX17, + NumberFormat::FORMAT_DATE_YYYYMMDD2, + NumberFormat::FORMAT_DATE_YYYYMMDDSLASH, + ] +``` + +## Force Numeric Field As Text Format + +Option to force auto-detected numeric value as text format. + +```php +Column::make('id')->exportFormat('@'), +Column::make('id')->exportFormat(NumberFormat::FORMAT_GENERAL), +Column::make('id')->exportFormat(NumberFormat::FORMAT_TEXT), +``` diff --git a/exports-purge.md b/exports-purge.md new file mode 100644 index 0000000..241af22 --- /dev/null +++ b/exports-purge.md @@ -0,0 +1,20 @@ +# Export Usage + +## Purging exported files + +On `app\Console\Kernel.php`, register the purge command + +```php +$schedule->command('datatables:purge-export')->weekly(); +``` + +## Export Filename + +You can set the export filename by setting the property. + +```php + + + + +``` From 6eade255b62b495ee637de274e3a30fc4af39880 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 14 Jul 2022 14:49:21 +0800 Subject: [PATCH 28/78] Remove file --- exports-purge.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/exports-purge.md b/exports-purge.md index 241af22..ee246f1 100644 --- a/exports-purge.md +++ b/exports-purge.md @@ -7,14 +7,3 @@ On `app\Console\Kernel.php`, register the purge command ```php $schedule->command('datatables:purge-export')->weekly(); ``` - -## Export Filename - -You can set the export filename by setting the property. - -```php - - - - -``` From dada81b0ab110757fcc938bcee7859c91aba3f07 Mon Sep 17 00:00:00 2001 From: Hamees Ahmed Khan <32523517+hameesakhan@users.noreply.github.com> Date: Tue, 19 Jul 2022 20:38:59 +0500 Subject: [PATCH 29/78] Added missing quote to highlight library names --- quick-starter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quick-starter.md b/quick-starter.md index 57c976b..152b3a6 100644 --- a/quick-starter.md +++ b/quick-starter.md @@ -34,7 +34,7 @@ php artisan ui bootstrap --auth yarn add datatables.net-bs4 datatables.net-buttons-bs4 datatables.net-select-bs4 datatables.net-searchpanes-bs4 ``` -> {tip} datatables.net-select-bs4` and `datatables.net-searchpanes-bs4` are only required if you want to use SearchPanes +> {tip} `datatables.net-select-bs4` and `datatables.net-searchpanes-bs4` are only required if you want to use SearchPanes ## Register datatables.net assets in bootstrap.js and app.scss From 94275f29f04631f93d2a1f6a48d188a2e3680ae9 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 13 Oct 2022 17:42:29 +0800 Subject: [PATCH 30/78] remove api --- documentation.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/documentation.md b/documentation.md index 9a7b5e9..226ef6a 100644 --- a/documentation.md +++ b/documentation.md @@ -2,11 +2,10 @@ - [Release Notes](/docs/{{package}}/{{version}}/releases) - [Upgrade Guide](/docs/{{package}}/{{version}}/upgrade) - [Contribution Guide](/docs/{{package}}/{{version}}/contributing) - - [Security Issues](/docs/{{package}}/{{version}}/security) - - [API Documentation](http://yajra.github.io/{{package}}/api/{{version}}) + - [Security Issues](/docs/{{package}}/{{version}}/security) - ## Getting Started - - [Introduction](/docs/{{package}}/{{version}}/introduction) + - [Introduction](/docs/{{package}}/{{version}}/introduction) - [Installation](/docs/{{package}}/{{version}}/installation) - [Demo Application](https://datatables.yajrabox.com/) - [Community Links](/docs/{{package}}/{{version}}/community-links) From b0999aab39084bb755a78535c89aa43c8785e514 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 19 Oct 2022 10:28:19 +0800 Subject: [PATCH 31/78] docs: update quick starter to work with vitejs --- quick-starter.md | 225 +++++++++++++++++++++++++---------------------- 1 file changed, 119 insertions(+), 106 deletions(-) diff --git a/quick-starter.md b/quick-starter.md index 152b3a6..85f03e7 100644 --- a/quick-starter.md +++ b/quick-starter.md @@ -1,161 +1,143 @@ # DataTables Quick Starter -## Create new project +## Create a new Laravel project ``` laravel new datatables cd datatables -cp .env.example .env -php artisan key:generate ``` -## Setup database and ENV configuration +## Setup Laravel UI -Create a new database and update `.env` file and set the datbase credentials. +```shell +composer require laravel/ui --dev +php artisan ui bootstrap --auth +``` -## Install package and publish assets +## Install Laravel DataTables +```shell +composer require yajra/laravel-datatables:^9.0 ``` -composer require yajra/laravel-datatables -php artisan vendor:publish --tag=datatables-buttons -``` +## Setup database and ENV configuration -## Setup Laravel UI +Create a new database and update `.env` file and set the database credentials. -``` -composer require laravel/ui --dev -php artisan ui bootstrap --auth +```shell +touch database/database.sqlite ``` -## Install Datatables.net assets +```dotenv +DB_CONNECTION=sqlite +DB_DATABASE=/absolute/path/to/database/database.sqlite +``` +```shell +php artisan migrate ``` -yarn add datatables.net-bs4 datatables.net-buttons-bs4 datatables.net-select-bs4 datatables.net-searchpanes-bs4 + +## Install Laravel DataTables Vite Assets + +```shell +npm i laravel-datatables-vite --save-dev ``` -> {tip} `datatables.net-select-bs4` and `datatables.net-searchpanes-bs4` are only required if you want to use SearchPanes +This will install the following packages: + +1. Bootstrap Icons +2. DataTables with Buttons and Select plugins for Bootstrap 5 +3. Laravel DataTables custom scripts -## Register datatables.net assets in bootstrap.js and app.scss +## Register the package js and css -Edit `resources/js/bootstrap.js` and add the following: +Edit `resources/js/app.js` and add the following: - require('bootstrap'); - require('datatables.net-bs4'); - require('datatables.net-buttons-bs4'); - require('datatables.net-select-bs4'); - require('datatables.net-searchpanes-bs4'); +```js +import './bootstrap'; +import 'laravel-datatables-vite'; +``` -Edit `resources/scss/app.scss` and add the following: +Edit `resources/sass/app.scss` and add the following: - // DataTables - @import "~datatables.net-bs4/css/dataTables.bootstrap4.css"; - @import "~datatables.net-buttons-bs4/css/buttons.bootstrap4.css"; - @import '~datatables.net-select-bs4/css/select.dataTables.css'; - @import '~datatables.net-searchpanes-dt/css/searchPanes.dataTables.css'; +```postcss +// Fonts +@import url('https://fonts.bunny.net/css?family=Nunito'); -## Compile assets +// Variables +@import 'variables'; -``` -yarn dev / watch / prod +// Bootstrap +@import 'bootstrap/scss/bootstrap'; + +// DataTables +@import 'bootstrap-icons/font/bootstrap-icons.css'; +@import "datatables.net-bs5/css/dataTables.bootstrap5.min.css"; +@import "datatables.net-buttons-bs5/css/buttons.bootstrap5.min.css"; +@import 'datatables.net-select-bs5/css/select.bootstrap5.css'; ``` -## Create controller and DataTable class +## Compile the assets ``` -php artisan make:controller UsersController -php artisan datatables:make Users +npm run dev ``` -### UsersController +## Create and update UsersDataTable -```php -namespace App\Http\Controllers; - -use App\DataTables\UsersDataTable; +Create a new DataTable class: -class UsersController extends Controller -{ - public function index(UsersDataTable $dataTable) - { - return $dataTable->render('users.index'); - } -} +```shell +php artisan datatables:make Users ``` -### UsersDataTable +Then, update the `getColumns()` with the users fields: ```php namespace App\DataTables; -use App\User; +use App\Models\User; +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 UsersDataTable extends DataTable { - /** - * Build DataTable class. - * - * @param mixed $query Results from query() method. - * @return \Yajra\DataTables\DataTableAbstract - */ - public function dataTable($query) + public function dataTable(QueryBuilder $query): EloquentDataTable { - return datatables() - ->eloquent($query) - ->addColumn('action', 'users.action'); + return (new EloquentDataTable($query))->setRowId('id'); } - /** - * Get query source of dataTable. - * - * @param \App\User $model - * @return \Illuminate\Database\Eloquent\Builder - */ - public function query(User $model) + public function query(User $model): QueryBuilder { return $model->newQuery(); } - /** - * Optional method if you want to use html builder. - * - * @return \Yajra\DataTables\Html\Builder - */ - public function html() + public function html(): HtmlBuilder { return $this->builder() ->setTableId('users-table') ->columns($this->getColumns()) ->minifiedAjax() - ->dom('Bfrtip') ->orderBy(1) - ->buttons( - Button::make('create'), - Button::make('export'), + ->selectStyleSingle() + ->buttons([ + Button::make('add'), + Button::make('excel'), + Button::make('csv'), + Button::make('pdf'), Button::make('print'), Button::make('reset'), - Button::make('reload') - ); + Button::make('reload'), + ]); } - /** - * Get columns. - * - * @return array - */ - protected function getColumns() + protected function getColumns(): array { return [ - Column::computed('action') - ->exportable(false) - ->printable(false) - ->width(60) - ->addClass('text-center'), Column::make('id'), Column::make('name'), Column::make('email'), @@ -164,26 +146,48 @@ class UsersDataTable extends DataTable ]; } - /** - * Get filename for export. - * - * @return string - */ - protected function filename() + protected function filename(): string + { + return 'Users_'.date('YmdHis'); + } +} +``` + +## Create and update the users controller + +Create a new controller and add the following: + +```shell +php artisan make:controller UsersController +``` + +```php +namespace App\Http\Controllers; + +use App\DataTables\UsersDataTable; + +class UsersController extends Controller +{ + public function index(UsersDataTable $dataTable) { - return 'Users_' . date('YmdHis'); + return $dataTable->render('users.index'); } } ``` -## Update app layout +## Update the default app layout -Add scripts before the body end tag of `resources/views/layouts/app.blade.php` +Add `@stack('scripts')` before the body end tag of `resources/views/layouts/app.blade.php` ``` - - +.... +
+ @yield('content') +
+ @stack('scripts') + + ``` ## Create users index file @@ -194,11 +198,18 @@ Create new file: `resources/views/users/index.blade.php`. @extends('layouts.app') @section('content') - {{$dataTable->table()}} +
+
+
Manage Users
+
+ {{ $dataTable->table() }} +
+
+
@endsection @push('scripts') - {{$dataTable->scripts()}} + {{ $dataTable->scripts(attributes: ['type' => 'module']) }} @endpush ``` @@ -207,7 +218,9 @@ Create new file: `resources/views/users/index.blade.php`. Update `routes/web.php`. ```php -Route::get('/users', 'UsersController@index')->name('users.index'); +use App\Http\Controllers\UsersController; + +Route::get('/users', [UsersController::class, 'index'])->name('users.index'); ``` ## Create dummy data using tinker @@ -216,7 +229,7 @@ Route::get('/users', 'UsersController@index')->name('users.index'); php artisan tinker Psy Shell v0.9.9 (PHP 7.2.22 — cli) by Justin Hileman ->>> factory('App\User', 100)->create() +>>> User::factory(100)->create() ``` ## Access Users DataTables From 163a1b533c29d895196e7c3b8e4491f3dab2e7bb Mon Sep 17 00:00:00 2001 From: mark-git07 Date: Sun, 23 Oct 2022 18:51:03 +0800 Subject: [PATCH 32/78] initial revisions for a few document files v10.0 --- add-column.md | 4 ++-- buttons-config.md | 10 +++++----- buttons-console.md | 12 ++++++------ buttons-custom.md | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/add-column.md b/add-column.md index 92e82c0..d5b984c 100644 --- a/add-column.md +++ b/add-column.md @@ -1,8 +1,8 @@ # Add Column -You can add a custom column on your response by using `addColumn` api. +You can add a custom column to your response by using the `addColumn` api. -> {note} added columns are assumed to be computed columns and not part of the database. Thus, search/sort will be disabled on those columns. If you need them, use the `editColumn` api instead. +> {note} added columns are assumed to be computed columns and not part of the database. Thus, search/sort will be disabled for those columns. If you need them, use the `editColumn` api instead. ## Add Column with Blade Syntax diff --git a/buttons-config.md b/buttons-config.md index 5b4260d..817b62e 100644 --- a/buttons-config.md +++ b/buttons-config.md @@ -12,8 +12,8 @@ Namespace configuration is used by the datatables command generator. ``` ### DataTable Base Namespace/Directory -This is the base namespace/directory to be created when a new DataTable was called. -This directory is appended on default Laravel namespace. +This is the base namespace/directory to be created when a new DataTable is called. +This directory is appended to the default Laravel namespace. **Usage:** ```php artisan datatables:make User``` @@ -24,8 +24,8 @@ This directory is appended on default Laravel namespace. **Export filename:** ```users_(timestamp)``` ### Model Option -This is the base namespace/directory where your model's are located. -This directory is appended on default Laravel namespace. +This is the base namespace/directory where your models are located. +This directory is appended to the default Laravel namespace. **Usage:** ```php artisan datatables:make Post --model``` **Output:** ```App\DataTables\PostDataTable``` **With Model:** ```App\Post`` @@ -33,7 +33,7 @@ This directory is appended on default Laravel namespace. ## PDF Generator -Set the PDF generator to be used when converting your dataTable to pdf. +Set the PDF generator to be used when converting your dataTable to PDF. Available generators are: `excel`, `snappy` diff --git a/buttons-console.md b/buttons-console.md index 7e88422..0efc0fc 100644 --- a/buttons-console.md +++ b/buttons-console.md @@ -18,7 +18,7 @@ In this example, we will create a DataTable service class. php artisan datatables:make Posts ``` -This will create an `PostsDataTable` class on `app\DataTables` directory. +This will create a `PostsDataTable` class in the `app\DataTables` directory. ```php namespace App\DataTables; @@ -101,7 +101,7 @@ In this example, we will pass a `--model` option to set the model to be used by php artisan datatables:make Posts --model ``` -This will generate a `App\DataTables\PostsDataTable` class that uses `App\Post` as the base model for our query. +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 @@ -194,12 +194,12 @@ This will allow to use a non-standard namespace if front-end and back-end models ### Action Option -In this example, we will pass a `--action` option to set a custom path for the action column view. +In this example, we will use the `--action` option to set a custom path for the action column view. ``` php artisan datatables:make Posts --action="client.action" ``` -If not provided, a default path will be used. It will needs to be changed thereafter. +If no path is provided, a default path will be used. It will need to be changed thereafter. ### Columns Option @@ -208,13 +208,13 @@ In this example, we will pass a `--columns` option to set the columns to be used ``` php artisan datatables:make Posts --columns="id,title,author" ``` -If not provided, a default set of columns will be used. It will needs to be manually changed thereafter. +If not provided, a default set of columns will be used. It will need to be manually changed thereafter. ## Creating a DataTable Scope service class -DataTable scope is class that we can use to limit our database search results based on the defined query scopes. +DataTable scope is a class that we can use to limit our database search results based on the defined query scopes. ``` php artisan datatables:scope ActiveUser diff --git a/buttons-custom.md b/buttons-custom.md index 9330875..0f178ca 100644 --- a/buttons-custom.md +++ b/buttons-custom.md @@ -1,9 +1,9 @@ # Custom Actions -You can enable custom actions on your buttons, as follows: +You can enable custom actions on your buttons as follows: Update `UsersDataTable` class and overload the `actions` property. Here we are -disabling the `csv` and `pdf` action (so they cannot be fired by hijacking the +disabling the `csv` and `pdf` actions (so they cannot be fired by hijacking their request) and enabling a `myCustomAction`. From 689ab8688c3a72cedc49ed593b3a88ad1777b00d Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 26 Oct 2022 19:48:19 +0800 Subject: [PATCH 33/78] docs: use h2 & h3 --- quick-starter.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/quick-starter.md b/quick-starter.md index 85f03e7..8c7ddc3 100644 --- a/quick-starter.md +++ b/quick-starter.md @@ -1,26 +1,26 @@ -# DataTables Quick Starter +## DataTables Quick Starter -## Create a new Laravel project +### Create a new Laravel project ``` laravel new datatables cd datatables ``` -## Setup Laravel UI +### Setup Laravel UI ```shell composer require laravel/ui --dev php artisan ui bootstrap --auth ``` -## Install Laravel DataTables +### Install Laravel DataTables ```shell composer require yajra/laravel-datatables:^9.0 ``` -## Setup database and ENV configuration +### Setup database and ENV configuration Create a new database and update `.env` file and set the database credentials. @@ -37,7 +37,7 @@ DB_DATABASE=/absolute/path/to/database/database.sqlite php artisan migrate ``` -## Install Laravel DataTables Vite Assets +### Install Laravel DataTables Vite Assets ```shell npm i laravel-datatables-vite --save-dev @@ -49,7 +49,7 @@ This will install the following packages: 2. DataTables with Buttons and Select plugins for Bootstrap 5 3. Laravel DataTables custom scripts -## Register the package js and css +### Register the package js and css Edit `resources/js/app.js` and add the following: @@ -77,13 +77,13 @@ Edit `resources/sass/app.scss` and add the following: @import 'datatables.net-select-bs5/css/select.bootstrap5.css'; ``` -## Compile the assets +### Compile the assets ``` npm run dev ``` -## Create and update UsersDataTable +### Create and update UsersDataTable Create a new DataTable class: @@ -153,7 +153,7 @@ class UsersDataTable extends DataTable } ``` -## Create and update the users controller +### Create and update the users controller Create a new controller and add the following: @@ -175,7 +175,7 @@ class UsersController extends Controller } ``` -## Update the default app layout +### Update the default app layout Add `@stack('scripts')` before the body end tag of `resources/views/layouts/app.blade.php` @@ -190,7 +190,7 @@ Add `@stack('scripts')` before the body end tag of `resources/views/layouts/app. ``` -## Create users index file +### Create users index file Create new file: `resources/views/users/index.blade.php`. @@ -213,7 +213,7 @@ Create new file: `resources/views/users/index.blade.php`. @endpush ``` -## Register users route +### Register users route Update `routes/web.php`. @@ -223,7 +223,7 @@ use App\Http\Controllers\UsersController; Route::get('/users', [UsersController::class, 'index'])->name('users.index'); ``` -## Create dummy data using tinker +### Create dummy data using tinker ```php php artisan tinker @@ -232,7 +232,7 @@ Psy Shell v0.9.9 (PHP 7.2.22 — cli) by Justin Hileman >>> User::factory(100)->create() ``` -## Access Users DataTables +### Access Users DataTables http://datatables.test/users From 09578ccdf0ea96395366de3bc9021299eb4f31c9 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 26 Oct 2022 19:57:05 +0800 Subject: [PATCH 34/78] Revert "docs: use h2 & h3" This reverts commit 689ab8688c3a72cedc49ed593b3a88ad1777b00d. --- quick-starter.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/quick-starter.md b/quick-starter.md index 8c7ddc3..85f03e7 100644 --- a/quick-starter.md +++ b/quick-starter.md @@ -1,26 +1,26 @@ -## DataTables Quick Starter +# DataTables Quick Starter -### Create a new Laravel project +## Create a new Laravel project ``` laravel new datatables cd datatables ``` -### Setup Laravel UI +## Setup Laravel UI ```shell composer require laravel/ui --dev php artisan ui bootstrap --auth ``` -### Install Laravel DataTables +## Install Laravel DataTables ```shell composer require yajra/laravel-datatables:^9.0 ``` -### Setup database and ENV configuration +## Setup database and ENV configuration Create a new database and update `.env` file and set the database credentials. @@ -37,7 +37,7 @@ DB_DATABASE=/absolute/path/to/database/database.sqlite php artisan migrate ``` -### Install Laravel DataTables Vite Assets +## Install Laravel DataTables Vite Assets ```shell npm i laravel-datatables-vite --save-dev @@ -49,7 +49,7 @@ This will install the following packages: 2. DataTables with Buttons and Select plugins for Bootstrap 5 3. Laravel DataTables custom scripts -### Register the package js and css +## Register the package js and css Edit `resources/js/app.js` and add the following: @@ -77,13 +77,13 @@ Edit `resources/sass/app.scss` and add the following: @import 'datatables.net-select-bs5/css/select.bootstrap5.css'; ``` -### Compile the assets +## Compile the assets ``` npm run dev ``` -### Create and update UsersDataTable +## Create and update UsersDataTable Create a new DataTable class: @@ -153,7 +153,7 @@ class UsersDataTable extends DataTable } ``` -### Create and update the users controller +## Create and update the users controller Create a new controller and add the following: @@ -175,7 +175,7 @@ class UsersController extends Controller } ``` -### Update the default app layout +## Update the default app layout Add `@stack('scripts')` before the body end tag of `resources/views/layouts/app.blade.php` @@ -190,7 +190,7 @@ Add `@stack('scripts')` before the body end tag of `resources/views/layouts/app. ``` -### Create users index file +## Create users index file Create new file: `resources/views/users/index.blade.php`. @@ -213,7 +213,7 @@ Create new file: `resources/views/users/index.blade.php`. @endpush ``` -### Register users route +## Register users route Update `routes/web.php`. @@ -223,7 +223,7 @@ use App\Http\Controllers\UsersController; Route::get('/users', [UsersController::class, 'index'])->name('users.index'); ``` -### Create dummy data using tinker +## Create dummy data using tinker ```php php artisan tinker @@ -232,7 +232,7 @@ Psy Shell v0.9.9 (PHP 7.2.22 — cli) by Justin Hileman >>> User::factory(100)->create() ``` -### Access Users DataTables +## Access Users DataTables http://datatables.test/users From f4bc1d09df91b856374867fdbebdc238bbff2601 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 11:59:44 +0800 Subject: [PATCH 35/78] docs: remove some badge --- introduction.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/introduction.md b/introduction.md index fc30ba1..aaa9b08 100644 --- a/introduction.md +++ b/introduction.md @@ -20,13 +20,10 @@ Official documentation of DataTables is available at [datatables.net](https://da ## Laravel DataTables -[![Join the chat at https://gitter.im/yajra/laravel-datatables](https://badges.gitter.im/yajra/laravel-datatables.svg)](https://gitter.im/yajra/laravel-datatables?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![License](https://poser.pugx.org/yajra/laravel-datatables-oracle/license)](https://packagist.org/packages/yajra/laravel-datatables-oracle) -[![Laravel 4.2|5.x](https://img.shields.io/badge/Laravel-4.2|5.x-orange.svg)](http://laravel.com) [![Latest Stable Version](https://poser.pugx.org/yajra/laravel-datatables-oracle/v/stable)](https://packagist.org/packages/yajra/laravel-datatables-oracle) -[![Build Status](https://travis-ci.org/yajra/laravel-datatables.svg?branch=master)](https://travis-ci.org/yajra/laravel-datatables) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yajra/{{package}}/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yajra/{{package}}/?branch=master) + [![Total Downloads](https://poser.pugx.org/yajra/laravel-datatables-oracle/downloads)](https://packagist.org/packages/yajra/laravel-datatables-oracle) Laravel DataTables is a package that handles the [server-side](https://www.datatables.net/manual/server-side) works of [DataTables](http://datatables.net) using [Laravel](http://laravel.com). From 83b8c1f6fc88bb49afa0e355e0aeff7e131cfc99 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 12:48:14 +0800 Subject: [PATCH 36/78] Update buttons-installation.md --- buttons-installation.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/buttons-installation.md b/buttons-installation.md index 424966c..438fafd 100644 --- a/buttons-installation.md +++ b/buttons-installation.md @@ -1,12 +1,19 @@ -# Buttons Plugin Installation +# Buttons Plugin -Github: https://github.com/yajra/laravel-datatables-buttons +A Laravel DataTables plugin for handling server-side exporting of table as csv, excel, pdf, etc. + + +## Installation Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-buttons:^9.0` +```shell +composer require yajra/laravel-datatables-buttons:^9.0 +``` + ## Configuration + > This step is optional if you are using Laravel 5.5 Open the file ```config/app.php``` and then add following service provider. @@ -21,6 +28,6 @@ Open the file ```config/app.php``` and then add following service provider. After completing the step above, use the following command to publish configuration & assets: -``` +```shell php artisan vendor:publish --tag=datatables-buttons ``` From 044a11ac884dbd77b9cac04e3b1ab88cd06ce5e7 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 12:49:48 +0800 Subject: [PATCH 37/78] docs: 5.5+ --- buttons-installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buttons-installation.md b/buttons-installation.md index 438fafd..839f35b 100644 --- a/buttons-installation.md +++ b/buttons-installation.md @@ -14,7 +14,7 @@ composer require yajra/laravel-datatables-buttons:^9.0 ## Configuration -> This step is optional if you are using Laravel 5.5 +> This step is optional if you are using Laravel 5.5+ Open the file ```config/app.php``` and then add following service provider. From 98c518e28a89e6f25d472ab3bfd1f6a888061552 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 12:52:20 +0800 Subject: [PATCH 38/78] docs: remove link to old tutz --- documentation.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/documentation.md b/documentation.md index 226ef6a..02896f0 100644 --- a/documentation.md +++ b/documentation.md @@ -5,14 +5,13 @@ - [Security Issues](/docs/{{package}}/{{version}}/security) - ## Getting Started - - [Introduction](/docs/{{package}}/{{version}}/introduction) - - [Installation](/docs/{{package}}/{{version}}/installation) + - [Introduction](/docs/{{package}}/{{version}}/introduction) + - [Installation](/docs/{{package}}/{{version}}/installation) - [Demo Application](https://datatables.yajrabox.com/) - [Community Links](/docs/{{package}}/{{version}}/community-links) - ## Tutorials - - [Quick Starter](/docs/{{package}}/{{version}}/quick-starter) - - [Service Implementation](https://datatables.yajrabox.com/service) + - [Quick Starter](/docs/{{package}}/{{version}}/quick-starter) - ## Configuration - [General Settings](/docs/{{package}}/{{version}}/general-settings) From a5608217bcb86b74167d0554a42dd19f64bc8e7f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 17:17:18 +0800 Subject: [PATCH 39/78] docs: bootcamp style quick starter --- quick-starter.md | 136 +++++++++++++++++++++++------------------------ 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/quick-starter.md b/quick-starter.md index 85f03e7..5922ebf 100644 --- a/quick-starter.md +++ b/quick-starter.md @@ -1,43 +1,41 @@ -# DataTables Quick Starter +# Quick Starter -## Create a new Laravel project + +## 01. Installing Laravel & DataTables -``` +### Quick Installation + +If you have already installed [Laravel Installer](https://laravel.com/docs#your-first-laravel-project) on your local machine, you may create a new project via laravel command: + +```shell laravel new datatables -cd datatables ``` -## Setup Laravel UI +After the project has been created, we will then install [Laravel UI](https://github.com/laravel/ui) and [Yajra DataTables](https://github.com/yajra/laravel-datatables) ```shell +cd datatables + composer require laravel/ui --dev php artisan ui bootstrap --auth -``` - -## Install Laravel DataTables -```shell composer require yajra/laravel-datatables:^9.0 ``` -## Setup database and ENV configuration - -Create a new database and update `.env` file and set the database credentials. +For simplicity, you may use SQLite to store your application's data. To instruct Laravel to use SQLite instead of MySQL, update your new application's `.env` file and remove all of the `DB_*` environment variables except for the `DB_CONNECTION` variable, which should be set to `sqlite`: ```shell touch database/database.sqlite ``` -```dotenv +```dotenv filename=.env DB_CONNECTION=sqlite -DB_DATABASE=/absolute/path/to/database/database.sqlite ``` -```shell -php artisan migrate -``` + +## 02. Install Laravel DataTables Vite -## Install Laravel DataTables Vite Assets +Next, we will install [Laravel DataTables Vite](https://github.com/yajra/laravel-datatables-vite) to simplify our frontend setup. ```shell npm i laravel-datatables-vite --save-dev @@ -45,22 +43,20 @@ npm i laravel-datatables-vite --save-dev This will install the following packages: -1. Bootstrap Icons -2. DataTables with Buttons and Select plugins for Bootstrap 5 -3. Laravel DataTables custom scripts - -## Register the package js and css +``` + - Bootstrap Icons + - DataTables with Buttons and Select plugins for Bootstrap 5 + - Laravel DataTables custom scripts +``` -Edit `resources/js/app.js` and add the following: +Once installed, we can now configure our scripts and css needed for our application. -```js +```js filename=resources/js/app.js import './bootstrap'; import 'laravel-datatables-vite'; ``` -Edit `resources/sass/app.scss` and add the following: - -```postcss +```postcss filename=resources/sass/app.scss // Fonts @import url('https://fonts.bunny.net/css?family=Nunito'); @@ -77,23 +73,24 @@ Edit `resources/sass/app.scss` and add the following: @import 'datatables.net-select-bs5/css/select.bootstrap5.css'; ``` -## Compile the assets +We just need to start the Vite development server to automatically recompile our JS, CSS and refresh the browser when we make changes to our Blade templates: -``` +```shell npm run dev ``` -## Create and update UsersDataTable + +## 03. Setup a Users DataTable -Create a new DataTable class: +Open a new terminal in your `datatables` project directory and run the following command: ```shell php artisan datatables:make Users ``` -Then, update the `getColumns()` with the users fields: +Next, we will configure our `UsersDataTable` and add the columns that we want to display. -```php +```php filename=app/DataTables/UsersDataTable.php namespace App\DataTables; use App\Models\User; @@ -135,7 +132,7 @@ class UsersDataTable extends DataTable ]); } - protected function getColumns(): array + public function getColumns(): array { return [ Column::make('id'), @@ -153,15 +150,14 @@ class UsersDataTable extends DataTable } ``` -## Create and update the users controller - -Create a new controller and add the following: + +## 04. Setup a Users Controller, View & Route ```shell php artisan make:controller UsersController ``` -```php +```php filename=app/Http/Controllers/UsersController.php namespace App\Http\Controllers; use App\DataTables\UsersDataTable; @@ -175,26 +171,7 @@ class UsersController extends Controller } ``` -## Update the default app layout - -Add `@stack('scripts')` before the body end tag of `resources/views/layouts/app.blade.php` - -``` -.... -
- @yield('content') -
- - @stack('scripts') - - -``` - -## Create users index file - -Create new file: `resources/views/users/index.blade.php`. - -```php +```blade filename=resources/views/users/index.blade.php @extends('layouts.app') @section('content') @@ -213,26 +190,49 @@ Create new file: `resources/views/users/index.blade.php`. @endpush ``` -## Register users route - -Update `routes/web.php`. - -```php +```php filename=routes/web.php use App\Http\Controllers\UsersController; Route::get('/users', [UsersController::class, 'index'])->name('users.index'); ``` -## Create dummy data using tinker + +## 05. Update the default app layout -```php +To be able to load our custom scripts, we need to add `@stack('scripts')` before the end of `body` tag in our `app.blade.php` layout. + +```blade filename=resources/views/layouts/app.blade.php +.... +
+ @yield('content') +
+ + @stack('scripts') + + +``` + + +## 06. Migrate and Seed Test Data + +```shell +php artisan migrate php artisan tinker +``` +```php Psy Shell v0.9.9 (PHP 7.2.22 — cli) by Justin Hileman >>> User::factory(100)->create() ``` -## Access Users DataTables +Our application should now be ready to run. + +```shell +php artisan serve +``` + +Once you have started the Artisan development server, your application will be accessible in your web browser at [http://localhost:8000]([http://localhost:8000). -http://datatables.test/users +We can now visit our [`/users`](http://localhost:8000/users) via route and see our users table. +Laravel DataTables Users From 29fab38c39990ada63b5fa655a3703857e26033d Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 17:50:27 +0800 Subject: [PATCH 40/78] fix: typo --- quick-starter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quick-starter.md b/quick-starter.md index 5922ebf..1f8fb34 100644 --- a/quick-starter.md +++ b/quick-starter.md @@ -233,6 +233,6 @@ php artisan serve Once you have started the Artisan development server, your application will be accessible in your web browser at [http://localhost:8000]([http://localhost:8000). -We can now visit our [`/users`](http://localhost:8000/users) via route and see our users table. +We can now visit our [`/users`](http://localhost:8000/users) route and see our users table. Laravel DataTables Users From 0f51be95f03a917ad256851cc0144d7472e81f70 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 17:54:00 +0800 Subject: [PATCH 41/78] use image from site --- quick-starter.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quick-starter.md b/quick-starter.md index 1f8fb34..e911865 100644 --- a/quick-starter.md +++ b/quick-starter.md @@ -233,6 +233,6 @@ php artisan serve Once you have started the Artisan development server, your application will be accessible in your web browser at [http://localhost:8000]([http://localhost:8000). -We can now visit our [`/users`](http://localhost:8000/users) route and see our users table. +We can now visit our [`/users`](http://localhost:8000/users) via route and see our users table. -Laravel DataTables Users +Laravel DataTables Users From 6f945e88d961a56c4caed50a0ced777499cfcf76 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 17:58:37 +0800 Subject: [PATCH 42/78] Update documentation.md --- documentation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation.md b/documentation.md index 02896f0..c1160d4 100644 --- a/documentation.md +++ b/documentation.md @@ -77,7 +77,7 @@ ### PLUGINS -- ## HTML Builder +- ## Html - [Installation](/docs/{{package}}/{{version}}/html-installation) - [Builder](/docs/{{package}}/{{version}}/html-builder) - [Table](/docs/{{package}}/{{version}}/html-builder-table) From 0a4795817c7a8a5320dcdc6f31d8ef429970f902 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 18:03:18 +0800 Subject: [PATCH 43/78] typo --- quick-starter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quick-starter.md b/quick-starter.md index e911865..7e96d71 100644 --- a/quick-starter.md +++ b/quick-starter.md @@ -233,6 +233,6 @@ php artisan serve Once you have started the Artisan development server, your application will be accessible in your web browser at [http://localhost:8000]([http://localhost:8000). -We can now visit our [`/users`](http://localhost:8000/users) via route and see our users table. +We can now visit our [`/users`](http://localhost:8000/users) route and see our users table. Laravel DataTables Users From 9832eaa53b62c524d33abc090bf1b3ab054c4a8f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 18:40:36 +0800 Subject: [PATCH 44/78] Update search-panes-starter.md --- search-panes-starter.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/search-panes-starter.md b/search-panes-starter.md index a9c96e9..9385858 100644 --- a/search-panes-starter.md +++ b/search-panes-starter.md @@ -5,11 +5,13 @@ allow the user to quickly filter the datatable after predefined filters. > {note} To use datatables you need to make sure that the npm packages `datatables.net-select-bs4` and `datatables.net-searchpanes-bs4` are installed and added to your `app.js`/`app.css` files. + ## Adding SearchPanes to the frontend To be able to see SearchPanes you need to either add them fixed in the dom (displayed at all time) or add a button which opens them as popup. + ### Adding SearchPanes fixed in the dom SearchPanes can be added to a table via the dom string, in it, they are marked with a `P` if you for example @@ -17,6 +19,7 @@ are using `Bfrtip` as dom you can use `PBfrtip` to display the SearchPanes at th to display them at the very bottom. Setting the dom String with the `\Yajra\DataTables\Html\Builder`: + ```php public function html() : \Yajra\DataTables\Html\Builder { @@ -34,6 +37,7 @@ public function html() : \Yajra\DataTables\Html\Builder } ``` + ### Adding SearchPanes with a button To add a button which opens the SearchPanes you need to make one extending `searchPanes`: @@ -58,6 +62,7 @@ public function html() : \Yajra\DataTables\Html\Builder } ``` + ## Adding SearchPanes to the backend The SearchPanes can be filled in the datatables declaration via the `searchPane()` method. The method takes the column From 3f40edc63960a55ce2764187afc3547e7ada1070 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 18:42:29 +0800 Subject: [PATCH 45/78] Update search-panes-starter.md --- search-panes-starter.md | 1 - 1 file changed, 1 deletion(-) diff --git a/search-panes-starter.md b/search-panes-starter.md index 9385858..55f09e3 100644 --- a/search-panes-starter.md +++ b/search-panes-starter.md @@ -5,7 +5,6 @@ allow the user to quickly filter the datatable after predefined filters. > {note} To use datatables you need to make sure that the npm packages `datatables.net-select-bs4` and `datatables.net-searchpanes-bs4` are installed and added to your `app.js`/`app.css` files. - ## Adding SearchPanes to the frontend To be able to see SearchPanes you need to either add them fixed in the dom (displayed at all time) or add a button which From 4a34b91b78b71f3839f73cc070c29569a4288557 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 18:44:40 +0800 Subject: [PATCH 46/78] remove demo app link --- documentation.md | 1 - 1 file changed, 1 deletion(-) diff --git a/documentation.md b/documentation.md index c1160d4..206ceba 100644 --- a/documentation.md +++ b/documentation.md @@ -7,7 +7,6 @@ - ## Getting Started - [Introduction](/docs/{{package}}/{{version}}/introduction) - [Installation](/docs/{{package}}/{{version}}/installation) - - [Demo Application](https://datatables.yajrabox.com/) - [Community Links](/docs/{{package}}/{{version}}/community-links) - ## Tutorials From 181c41d997f61651d9332753e14ff61455a2a18a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 18:49:55 +0800 Subject: [PATCH 47/78] Update response-array.md --- response-array.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/response-array.md b/response-array.md index 59270ee..aa73ff1 100644 --- a/response-array.md +++ b/response-array.md @@ -1,6 +1,6 @@ # Array Response -Array response is the default response of DataTables. +The default response of the package is an array of objects. If you prefer to return an array response, use `make(false)`. ```php use DataTables; @@ -10,7 +10,7 @@ Route::get('user-data', function() { return DataTables::eloquent($model) ->addColumn('intro', 'Hi {{$name}}!') - ->make(); + ->make(false); }); ``` From d36787f2b5da1c7e498c239b4b3848c4405ab4e3 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 19:01:18 +0800 Subject: [PATCH 48/78] Update html-builder.md --- html-builder.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/html-builder.md b/html-builder.md index 7faf9c1..a39d6de 100644 --- a/html-builder.md +++ b/html-builder.md @@ -11,6 +11,7 @@ You can use the `Builder` class by using Dependency Injection. use Yajra\DataTables\Html\Builder; Route::get('users', function(Builder $builder) { + // }); ``` @@ -37,9 +38,10 @@ Route::get('users', function(DataTables $dataTable) { ## Html Builder Example -```php +```php filename=routes/web.php use DataTables; use Yajra\DataTables\Html\Builder; +use Yajra\DataTables\Html\Column; Route::get('users', function(Builder $builder) { if (request()->ajax()) { @@ -47,27 +49,26 @@ Route::get('users', function(Builder $builder) { } $html = $builder->columns([ - ['data' => 'id', 'name' => 'id', 'title' => 'Id'], - ['data' => 'name', 'name' => 'name', 'title' => 'Name'], - ['data' => 'email', 'name' => 'email', 'title' => 'Email'], - ['data' => 'created_at', 'name' => 'created_at', 'title' => 'Created At'], - ['data' => 'updated_at', 'name' => 'updated_at', 'title' => 'Updated At'], + Column::make('id), + Column::make('name), + Column::make('email), + Column::make('created_at), + Column::make('updated_at), ]); return view('users.index', compact('html')); }); ``` -On your `resources/views/users/index.blade.php`. -```php +```php filename=resources/views/users/index.blade.php @extends('app') @section('contents') - {!! $html->table() !!} + {{ $html->table() }} @endsection @push('scripts') - {!! $html->scripts() !!} + {{ $html->scripts() }} @endpush ``` From 01be62e252bbafe361c274004ecb7179e2540f63 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 27 Oct 2022 19:05:01 +0800 Subject: [PATCH 49/78] Update html-builder.md --- html-builder.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/html-builder.md b/html-builder.md index a39d6de..4339798 100644 --- a/html-builder.md +++ b/html-builder.md @@ -39,24 +39,25 @@ Route::get('users', function(DataTables $dataTable) { ## Html Builder Example ```php filename=routes/web.php -use DataTables; +use Yajra\DataTables\Facades\DataTables; use Yajra\DataTables\Html\Builder; use Yajra\DataTables\Html\Column; +use App\Models\User; Route::get('users', function(Builder $builder) { - if (request()->ajax()) { + if (request()->ajax()) { return DataTables::of(User::query())->toJson(); } - $html = $builder->columns([ - Column::make('id), - Column::make('name), - Column::make('email), - Column::make('created_at), - Column::make('updated_at), - ]); + $html = $builder->columns([ + Column::make('id'), + Column::make('name'), + Column::make('email'), + Column::make('created_at'), + Column::make('updated_at'), + ]); - return view('users.index', compact('html')); + return view('users.index', compact('html')); }); ``` From b5b423ab18fa580fa3526656a7b8045609d36cf9 Mon Sep 17 00:00:00 2001 From: Emmanuel Joseph Beron Date: Thu, 27 Oct 2022 23:48:34 +0800 Subject: [PATCH 50/78] Fix typo --- engine-eloquent.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine-eloquent.md b/engine-eloquent.md index e2874c9..f68e4d0 100644 --- a/engine-eloquent.md +++ b/engine-eloquent.md @@ -1,7 +1,7 @@ # Eloquent Data Source You may use Laravel's Eloquent Model as data source for your dataTables. -You can look at `Yajra\DataTables\EloquentDataTable` class which handles the conversion of your Eloquent Model into a readbale DataTable API response. +You can look at `Yajra\DataTables\EloquentDataTable` class which handles the conversion of your Eloquent Model into a readable DataTable API response. ## Eloquent via Factory From f21ba2e56950cc90123e0938b994fcfaec0afe44 Mon Sep 17 00:00:00 2001 From: Emmanuel Joseph Beron Date: Thu, 27 Oct 2022 23:49:07 +0800 Subject: [PATCH 51/78] Fix typo --- engine-collection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine-collection.md b/engine-collection.md index 3b8bed0..418ccc4 100644 --- a/engine-collection.md +++ b/engine-collection.md @@ -1,7 +1,7 @@ # Collection Data Source You may use Laravel's Collection as data source for your dataTables. -You can look at `Yajra\DataTables\CollectionDataTable` class which handles the conversion of your Collection into a readbale DataTable API response. +You can look at `Yajra\DataTables\CollectionDataTable` class which handles the conversion of your Collection into a readable DataTable API response. ## Collection via Factory From e024fbfb8e4c2ba624f3788977141facc2e43faa Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 3 Nov 2022 13:06:08 +0800 Subject: [PATCH 52/78] Update search-panes-starter.md --- search-panes-starter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search-panes-starter.md b/search-panes-starter.md index 55f09e3..969e947 100644 --- a/search-panes-starter.md +++ b/search-panes-starter.md @@ -1,4 +1,4 @@ -# Add SearchPane +# SearchPanes Extension [SearchPanes](https://datatables.net/extensions/searchpanes/) ([example](https://datatables.net/extensions/searchpanes/examples/initialisation/simple.html)) allow the user to quickly filter the datatable after predefined filters. From a542888d5b8c4382df2101cf53fc660588e75927 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 3 Nov 2022 13:06:59 +0800 Subject: [PATCH 53/78] Update documentation.md --- documentation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation.md b/documentation.md index 206ceba..14788f5 100644 --- a/documentation.md +++ b/documentation.md @@ -61,7 +61,7 @@ - [Order By Nulls Last](/docs/{{package}}/{{version}}/order-by-nulls-last) - ## SearchPanes - - [Add SearchPanes](/docs/{{package}}/{{version}}/search-panes-starter) + - [SearchPanes Extension](/docs/{{package}}/{{version}}/search-panes-starter) - [Hide Columns in SearchPanes](/docs/{{package}}/{{version}}/search-panes-hide-columns) - [Further options](/docs/{{package}}/{{version}}/search-panes-options) From 178e1c04c762cb30e2bf4bff3c11c49f73bdc3ce Mon Sep 17 00:00:00 2001 From: Arne Perschke Date: Sat, 14 Jan 2023 13:26:52 +0100 Subject: [PATCH 54/78] Tweaked SearchPanes chapter titles --- search-panes-hide-columns.md | 2 +- search-panes-starter.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/search-panes-hide-columns.md b/search-panes-hide-columns.md index 3064861..9d51f67 100644 --- a/search-panes-hide-columns.md +++ b/search-panes-hide-columns.md @@ -1,4 +1,4 @@ -# Hide Columns in SearchPanes +# Exclude Columns Some columns you might not want in your SearchPanes, to hide them you can add `->searchPanes(false)` in your column definition: diff --git a/search-panes-starter.md b/search-panes-starter.md index 969e947..c363b22 100644 --- a/search-panes-starter.md +++ b/search-panes-starter.md @@ -1,4 +1,4 @@ -# SearchPanes Extension +# Getting Started [SearchPanes](https://datatables.net/extensions/searchpanes/) ([example](https://datatables.net/extensions/searchpanes/examples/initialisation/simple.html)) allow the user to quickly filter the datatable after predefined filters. From dfbf5456b01bddd092cabbdf922722e9159aa702 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 15:32:22 +0800 Subject: [PATCH 55/78] Update installation.md --- installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation.md b/installation.md index 2db07f1..95e7af2 100644 --- a/installation.md +++ b/installation.md @@ -28,7 +28,7 @@ composer require yajra/laravel-datatables-oracle:"^10.0" If you are using most of the DataTables plugins like Buttons & Html, you can alternatively use the all-in-one installer package. ```bash -composer require yajra/laravel-datatables:^9.0 +composer require yajra/laravel-datatables:^10.0 ``` From 20aa69eb46ae4cb750b81a878e62f7bb9da78f2e Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 20:15:28 +0800 Subject: [PATCH 56/78] docs: remove package version --- quick-starter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quick-starter.md b/quick-starter.md index 7e96d71..fe09e60 100644 --- a/quick-starter.md +++ b/quick-starter.md @@ -19,7 +19,7 @@ cd datatables composer require laravel/ui --dev php artisan ui bootstrap --auth -composer require yajra/laravel-datatables:^9.0 +composer require yajra/laravel-datatables ``` For simplicity, you may use SQLite to store your application's data. To instruct Laravel to use SQLite instead of MySQL, update your new application's `.env` file and remove all of the `DB_*` environment variables except for the `DB_CONNECTION` variable, which should be set to `sqlite`: From 79bda837512eeca782b898572cd911f4ea472324 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 23:47:09 +0800 Subject: [PATCH 57/78] docs: laravel 10 + vitejs setup --- editor-tutorial.md | 173 +++++++++++++++++++++++++++++---------------- 1 file changed, 113 insertions(+), 60 deletions(-) diff --git a/editor-tutorial.md b/editor-tutorial.md index cf453b2..f12d42b 100644 --- a/editor-tutorial.md +++ b/editor-tutorial.md @@ -5,11 +5,13 @@ See [DataTables Editor](https://editor.datatables.net/purchase/index) for detail ## Pre-requisites -This tutorial requires https://yajrabox.com/docs/laravel-datatables/master/quick-starter. +This tutorial requires https://yajrabox.com/docs/laravel-datatables/10.0/quick-starter. ## Install DataTables Editor assets. - yarn add datatables.net-editor datatables.net-editor-bs4 datatables.net-select-bs4 +```sh +npm i datatables.net-editor datatables.net-editor-bs5 +``` ## Editor License @@ -17,107 +19,158 @@ Copy and rename your `Editor.XX.zip` to `Editor.zip` and move it to project fold ## Register postinstall script to package.json +```json "scripts": { - "postinstall": "node ./node_modules/datatables.net-editor/install.js ./Editor.zip", - "dev": "npm run development", - ..... + "dev": "vite", + "build": "vite build", + "postinstall": "node node_modules/datatables.net-editor/install.js ./Editor.zip" }, +``` -## Register editor script on `resources/js/bootstrap.js` - - try { - window.Popper = require('popper.js').default; - window.$ = window.jQuery = require('jquery'); +## Register editor script on `resources/js/app.js` - require('bootstrap'); - require('datatables.net-bs4'); - require('datatables.net-buttons-bs4'); - require('datatables.net-select-bs4'); - require('datatables.net-editor-bs4'); - } catch (e) {} +```js +import './bootstrap'; +import 'laravel-datatables-vite'; +import "datatables.net-editor"; +import Editor from "datatables.net-editor-bs5"; +Editor(window, $); +``` ## Add editor styles on `resources/sass/app.scss`. - @import "~datatables.net-select-bs4/css/select.bootstrap4.css"; - @import "~datatables.net-editor-bs4/css/editor.bootstrap4.css"; - -## Recompile assets. +```css +// Fonts +@import url('https://fonts.bunny.net/css?family=Nunito'); - yarn - yarn watch / dev / prod +// Variables +@import 'variables'; +// Bootstrap +@import 'bootstrap/scss/bootstrap'; -## Update UsersDataTable and register the Editor buttons. - -> Note: CREATE button is in conflict with `buttons.server-side.js`. You need to remove the create button or rename it to something else like `add` button. - - DataTable.ext.buttons.add = { - className: 'buttons-add', +// DataTables +@import 'bootstrap-icons/font/bootstrap-icons.css'; +@import "datatables.net-bs5/css/dataTables.bootstrap5.css"; +@import "datatables.net-buttons-bs5/css/buttons.bootstrap5.css"; +@import "datatables.net-editor-bs5/css/editor.bootstrap5.css"; +@import 'datatables.net-select-bs5/css/select.bootstrap5.css'; +``` - text: function (dt) { - return ' ' + dt.i18n('buttons.add', 'Create'); - }, +## Recompile assets. - action: function (e, dt, button, config) { - window.location = window.location.href.replace(/\/+$/, "") + '/create'; - } - }; +```sh +npm run dev +``` ### UsersDataTable.php Create a new editor instance and add some fields for name and email. ```php +namespace App\DataTables; + +use App\Models\User; +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 UsersDataTable extends DataTable +{ /** * Build DataTable class. * - * @param mixed $query Results from query() method. - * @return \Yajra\DataTables\DataTableAbstract + * @param QueryBuilder $query Results from query() method. + * @return \Yajra\DataTables\EloquentDataTable + */ + public function dataTable(QueryBuilder $query): EloquentDataTable + { + return (new EloquentDataTable($query)) + ->addColumn('action', 'users.action') + ->setRowId('id'); + } + + /** + * Get query source of dataTable. + * + * @param \App\Models\User $model + * @return \Illuminate\Database\Eloquent\Builder */ - public function dataTable($query) + public function query(User $model): QueryBuilder { - return datatables() - ->eloquent($query) - ->setRowId('id') // Set the RowID - ... + return $model->newQuery(); } - public function html() + /** + * Optional method if you want to use html builder. + * + * @return \Yajra\DataTables\Html\Builder + */ + public function html(): HtmlBuilder { return $this->builder() ->setTableId('users-table') ->columns($this->getColumns()) ->minifiedAjax() - ->dom('Bfrtip') ->orderBy(1) - ->buttons( + ->selectStyleSingle() + ->editors([ + Editor::make() + ->fields([ + Fields\Text::make('name'), + Fields\Text::make('email'), + ]), + ]) + ->buttons([ Button::make('create')->editor('editor'), Button::make('edit')->editor('editor'), Button::make('remove')->editor('editor'), - Button::make('export'), + Button::make('excel'), + Button::make('csv'), + Button::make('pdf'), Button::make('print'), Button::make('reset'), - Button::make('reload') - ) - ->editor( - Editor::make() - ->fields([ - Fields\Text::make('name'), - Fields\Text::make('email'), - Fields\Password::make('password'), - ]) - ); + Button::make('reload'), + ]); + } + + /** + * Get the dataTable columns definition. + * + * @return array + */ + public function getColumns(): array + { + return [ + Column::make('id'), + Column::make('name'), + Column::make('email'), + Column::make('created_at'), + Column::make('updated_at'), + ]; + } + + /** + * Get filename for export. + * + * @return string + */ + protected function filename(): string + { + return 'Users_'.date('YmdHis'); } +} ``` ## Create Editor Class to handle CRUD actions. -``` +```sh php artisan datatables:editor Users ``` @@ -125,13 +178,13 @@ php artisan datatables:editor Users Edit `routes/web.php` and register the store user route. -``` +```php Route::post('/users', 'UsersController@store')->name('users.store'); ``` ## Update users controller -``` +```php namespace App\Http\Controllers; use Illuminate\Http\Request; From 94bd5300d3d977b0ca885abd98197c14bebdc0dc Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 23:55:23 +0800 Subject: [PATCH 58/78] fix: route --- editor-tutorial.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/editor-tutorial.md b/editor-tutorial.md index f12d42b..fdcc56b 100644 --- a/editor-tutorial.md +++ b/editor-tutorial.md @@ -179,7 +179,8 @@ php artisan datatables:editor Users Edit `routes/web.php` and register the store user route. ```php -Route::post('/users', 'UsersController@store')->name('users.store'); +Route::get('/users', [App\Http\Controllers\UsersController::class, 'index'])->name('users.index'); +Route::post('/users', [App\Http\Controllers\UsersController::class, 'store'])->name('users.store'); ``` ## Update users controller From bfed2fdbdbf920ef0906a9201007fb2b61f3d46b Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 21 Feb 2023 00:23:30 +0800 Subject: [PATCH 59/78] docs: add postinstall first --- editor-tutorial.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/editor-tutorial.md b/editor-tutorial.md index fdcc56b..94d7aad 100644 --- a/editor-tutorial.md +++ b/editor-tutorial.md @@ -7,12 +7,6 @@ See [DataTables Editor](https://editor.datatables.net/purchase/index) for detail This tutorial requires https://yajrabox.com/docs/laravel-datatables/10.0/quick-starter. -## Install DataTables Editor assets. - -```sh -npm i datatables.net-editor datatables.net-editor-bs5 -``` - ## Editor License Copy and rename your `Editor.XX.zip` to `Editor.zip` and move it to project folder. @@ -27,6 +21,12 @@ Copy and rename your `Editor.XX.zip` to `Editor.zip` and move it to project fold }, ``` +## Install DataTables Editor assets. + +```sh +npm i datatables.net-editor datatables.net-editor-bs5 +``` + ## Register editor script on `resources/js/app.js` ```js From 944538f984a439f5f2b503ddd41231c3770c84be Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 21 Feb 2023 00:25:08 +0800 Subject: [PATCH 60/78] docs: shorter title --- editor-tutorial.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/editor-tutorial.md b/editor-tutorial.md index 94d7aad..caff59b 100644 --- a/editor-tutorial.md +++ b/editor-tutorial.md @@ -1,4 +1,4 @@ -# Creating a Laravel Full CRUD with DataTables Editor. +# Laravel 10 CRUD with DataTables Editor. Before we begin, please be reminded that the Editor library that we are going to use here requires a paid license. See [DataTables Editor](https://editor.datatables.net/purchase/index) for details. @@ -91,9 +91,7 @@ class UsersDataTable extends DataTable */ public function dataTable(QueryBuilder $query): EloquentDataTable { - return (new EloquentDataTable($query)) - ->addColumn('action', 'users.action') - ->setRowId('id'); + return (new EloquentDataTable($query))->setRowId('id'); } /** From a65a0b63fb4c2bab34a13ac3a3024eed6e20d6ce Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 21 Feb 2023 12:29:00 +0800 Subject: [PATCH 61/78] docs: laravel 9 & 10 install docs --- installation.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/installation.md b/installation.md index 95e7af2..83c15e8 100644 --- a/installation.md +++ b/installation.md @@ -11,7 +11,7 @@ ### Requirements -- [Laravel 9+](https://github.com/laravel/framework) +- [Laravel 9|10](https://github.com/laravel/framework) - [jQuery DataTables v1.10.x](http://datatables.net/) @@ -21,6 +21,14 @@ 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: +#### Laravel 9 + +```bash +composer require yajra/laravel-datatables-oracle:"^9.0" +``` + +#### Laravel 10 + ```bash composer require yajra/laravel-datatables-oracle:"^10.0" ``` From 39150e363c354df30161c214661e09473592380d Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 21 Feb 2023 12:30:18 +0800 Subject: [PATCH 62/78] docs: fix installer --- installation.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/installation.md b/installation.md index 83c15e8..e24f5c0 100644 --- a/installation.md +++ b/installation.md @@ -21,19 +21,19 @@ 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: -#### Laravel 9 - ```bash -composer require yajra/laravel-datatables-oracle:"^9.0" +composer require yajra/laravel-datatables-oracle:"^10.0" ``` -#### Laravel 10 +If you are using most of the DataTables plugins like Buttons & Html, you can alternatively use the all-in-one installer package. + +#### Laravel 9 ```bash -composer require yajra/laravel-datatables-oracle:"^10.0" +composer require yajra/laravel-datatables:"^9.0" ``` -If you are using most of the DataTables plugins like Buttons & Html, you can alternatively use the all-in-one installer package. +#### Laravel 10 ```bash composer require yajra/laravel-datatables:^10.0 From 42b1e616e47ec8008d0963412462c58ca893920e Mon Sep 17 00:00:00 2001 From: nikunjkothiya <76523698+nikunjkothiya@users.noreply.github.com> Date: Fri, 12 May 2023 12:07:13 +0530 Subject: [PATCH 63/78] Update row-options.md Some tag information updated as per division. --- row-options.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/row-options.md b/row-options.md index 11c975e..50b0a5d 100644 --- a/row-options.md +++ b/row-options.md @@ -49,7 +49,7 @@ Setting row class via `blade` string. ## Row Data -Setting row class via `closure`. +Setting row data via `closure`. ```php ->setRowData([ @@ -62,7 +62,7 @@ Setting row class via `closure`. ]) ``` -Setting row class via `blade` string. +Setting row data via `blade` string. ```php ->setRowData([ @@ -74,7 +74,7 @@ Setting row class via `blade` string. ## Row Attributes -Setting row class via `closure`. +Setting row attribute via `closure`. ```php ->setRowAttr([ @@ -84,10 +84,10 @@ Setting row class via `closure`. ]) ``` -Setting row class via `blade` string. +Setting row attribute via `blade` string. ```php ->setRowAttr([ 'color' => '{{$color}}', ]) -``` \ No newline at end of file +``` From 8843dac44cdf3a83599a36829438b813498307fe Mon Sep 17 00:00:00 2001 From: Juan Carlos <16903487+carlosJCVC@users.noreply.github.com> Date: Tue, 23 Apr 2024 19:38:37 -0400 Subject: [PATCH 64/78] Update installation.md --- installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation.md b/installation.md index e24f5c0..eb5a0b5 100644 --- a/installation.md +++ b/installation.md @@ -43,7 +43,7 @@ composer require yajra/laravel-datatables:^10.0 ### Configuration > This step is optional if you are using Laravel 5.5+ -Open the file ```config/app.php``` and then add following service provider. +Open the file ```config/app.php``` or ```bootstrap/providers.php``` for Laravel 11 then add following service provider. ```php 'providers' => [ From 88f915904de44c11d04e3649f41c23bc3a38aeb2 Mon Sep 17 00:00:00 2001 From: Murtaja Ahmed Noyeem <42427285+Muurtaja@users.noreply.github.com> Date: Sun, 26 May 2024 15:23:19 +0600 Subject: [PATCH 65/78] fix: Ensure $actions property is explicitly typed as array in UserDataTable This commit fixes a type error in the UserDataTable class by explicitly typing the $actions property as an array. This change aligns with the expected type in the Yajra\DataTables\Services\DataTable class, preventing runtime errors and ensuring consistent data handling. - Updated the $actions property declaration from `protected $actions = ['print', 'excel', 'myCustomAction'];` to `protected array $actions = ['print', 'excel', 'myCustomAction'];`. - This change leverages PHP's property type declaration feature to enforce that $actions is always an array. - The modification enhances code robustness and readability, ensuring type safety and preventing potential issues related to incorrect data types. By making this update, the UserDataTable class now correctly adheres to the expected data structure, improving overall stability and maintainability. --- buttons-custom.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buttons-custom.md b/buttons-custom.md index 0f178ca..089a318 100644 --- a/buttons-custom.md +++ b/buttons-custom.md @@ -15,7 +15,7 @@ use Yajra\DataTables\Services\DataTable; class UsersDataTable extends DataTable { - protected $actions = ['print', 'excel', 'myCustomAction']; + protected array $actions = ['print', 'excel', 'myCustomAction']; public function html() { From a1dac6fe2e1e3742fc432dc6704d213df21031cd Mon Sep 17 00:00:00 2001 From: Milad Abdi Date: Sun, 16 Jun 2024 08:53:06 +0330 Subject: [PATCH 66/78] Refactor 'fastExcel' and 'fastExcelCallback' properties and method return type --- buttons-fast-excel.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/buttons-fast-excel.md b/buttons-fast-excel.md index fa04177..6e09a2b 100644 --- a/buttons-fast-excel.md +++ b/buttons-fast-excel.md @@ -9,14 +9,14 @@ FastExcel integration uses cursor behind the scene thus eager loaded columns wil ## Usage 1. Install `fast-excel` using `composer require rap2hpoutre/fast-excel`. -2. Create a dataTable class `php artisan datatables:make Users` +2. Create a dataTable class `php artisan datatables:make Users`. 3. Adjust `UsersDataTable` as needed. 4. Set property `$fastExcel = true`. ```php class UsersDataTable extends DataTable { - protected $fastExcel = true; + protected bool $fastExcel = true; ... } @@ -33,7 +33,7 @@ class UsersDataTable extends DataTable class UsersDataTable extends DataTable { protected $fastExcel = true; - protected $fastExcelCallback = false; + protected bool $fastExcelCallback = false; ``` @@ -46,9 +46,9 @@ Just override the `fastExcelCallback` method: ```php class UsersDataTable extends DataTable { - protected $fastExcel = true; + protected bool $fastExcel = true; - public function fastExcelCallback() + public function fastExcelCallback() \Closure { return function ($row) { return [ @@ -59,4 +59,4 @@ class UsersDataTable extends DataTable } ... -``` \ No newline at end of file +``` From a7880363e786d867918a7d3e80c5abca7f9a147b Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 18 Jun 2024 09:13:51 +0800 Subject: [PATCH 67/78] docs: Update buttons-fast-excel.md --- buttons-fast-excel.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buttons-fast-excel.md b/buttons-fast-excel.md index 6e09a2b..4d0819e 100644 --- a/buttons-fast-excel.md +++ b/buttons-fast-excel.md @@ -32,12 +32,12 @@ class UsersDataTable extends DataTable ```php class UsersDataTable extends DataTable { - protected $fastExcel = true; + protected bool $fastExcel = true; protected bool $fastExcelCallback = false; ``` -2. Exported file will now be based on how your query was structured. No header formatting and all selected columns in sql will be included in the output. +2. The exported file will now be based on your query's structure. No header formatting and all selected columns in sql will be included in the output. ## Using custom callback From fcdb88be30db419b7b15414021ab19bc2593ecc1 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 18 Jun 2024 13:14:20 +0800 Subject: [PATCH 68/78] docs: bump version --- buttons-installation.md | 2 +- fractal-installation.md | 2 +- html-installation.md | 2 +- installation.md | 14 +++----------- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/buttons-installation.md b/buttons-installation.md index 839f35b..45129b3 100644 --- a/buttons-installation.md +++ b/buttons-installation.md @@ -8,7 +8,7 @@ A Laravel DataTables plugin for handling server-side exporting of table as csv, Run the following command in your project to get the latest version of the plugin: ```shell -composer require yajra/laravel-datatables-buttons:^9.0 +composer require yajra/laravel-datatables-buttons:^11.0 ``` diff --git a/fractal-installation.md b/fractal-installation.md index e210f6b..6b53643 100644 --- a/fractal-installation.md +++ b/fractal-installation.md @@ -4,7 +4,7 @@ Github: https://github.com/yajra/laravel-datatables-fractal Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-fractal:^9.0` +`composer require yajra/laravel-datatables-fractal:^11.0` ## Configuration > This step is optional if you are using Laravel 5.5 diff --git a/html-installation.md b/html-installation.md index 507ce61..45a3f70 100644 --- a/html-installation.md +++ b/html-installation.md @@ -6,7 +6,7 @@ Github: https://github.com/yajra/laravel-datatables-html Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-html:^9.0` +`composer require yajra/laravel-datatables-html:^11.0` ## Configuration diff --git a/installation.md b/installation.md index eb5a0b5..dd7a8dd 100644 --- a/installation.md +++ b/installation.md @@ -11,7 +11,7 @@ ### Requirements -- [Laravel 9|10](https://github.com/laravel/framework) +- [Laravel 11](https://github.com/laravel/framework) - [jQuery DataTables v1.10.x](http://datatables.net/) @@ -22,21 +22,13 @@ 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:"^11.0" ``` If you are using most of the DataTables plugins like Buttons & Html, you can alternatively use the all-in-one installer package. -#### Laravel 9 - -```bash -composer require yajra/laravel-datatables:"^9.0" -``` - -#### Laravel 10 - ```bash -composer require yajra/laravel-datatables:^10.0 +composer require yajra/laravel-datatables:^11.0 ``` From 6c8de02d3e8ca55d1340ff7980ba646cd17ddfdd Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 18 Jun 2024 13:19:06 +0800 Subject: [PATCH 69/78] docs: editor version --- editor-installation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor-installation.md b/editor-installation.md index c4c95b6..8418b18 100644 --- a/editor-installation.md +++ b/editor-installation.md @@ -11,14 +11,14 @@ A [premium license](https://editor.datatables.net/purchase/index) is required to Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-editor:^1.0` +`composer require yajra/laravel-datatables-editor:^11.0` ## Configuration > This step is optional if you are using Laravel 5.5 -Open the file ```config/app.php``` and then add following service provider. +Open the file ```config/app.php``` and then add the following service provider. ```php 'providers' => [ From 48e1ed74200b7b8a756af5ef5d7d29f005e2eeaf Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 16 Oct 2024 09:08:55 +0800 Subject: [PATCH 70/78] docs: use DataTables v2 --- installation.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installation.md b/installation.md index dd7a8dd..bd054b2 100644 --- a/installation.md +++ b/installation.md @@ -12,7 +12,7 @@ ### Requirements - [Laravel 11](https://github.com/laravel/framework) -- [jQuery DataTables v1.10.x](http://datatables.net/) +- [DataTables v2.x](http://datatables.net/) ### Installing Laravel DataTables @@ -25,7 +25,7 @@ Run the following command in your project to get the latest version of the packa composer require yajra/laravel-datatables-oracle:"^11.0" ``` -If you are using most of the DataTables plugins like Buttons & Html, you can alternatively use the all-in-one installer package. +If you use most of the DataTables plugins like Buttons & HTML, you can use the all-in-one installer package. ```bash composer require yajra/laravel-datatables:^11.0 @@ -35,7 +35,7 @@ composer require yajra/laravel-datatables:^11.0 ### Configuration > This step is optional if you are using Laravel 5.5+ -Open the file ```config/app.php``` or ```bootstrap/providers.php``` for Laravel 11 then add following service provider. +Open the file ```config/app.php``` or ```bootstrap/providers.php``` for Laravel 11 then add the following service provider. ```php 'providers' => [ From fad9106a4b19dd710aad701be0f764dced8f9da2 Mon Sep 17 00:00:00 2001 From: Khaled Huthaily Date: Mon, 11 Nov 2024 13:39:59 -0700 Subject: [PATCH 71/78] use `query()` instead of deprecated `queryBuilder()` Starting from v10.x, `queryBuilder()` is deprecated, and `query()` should be used instead. However, the examples still use `queryBuilder()`. --- engine-query.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine-query.md b/engine-query.md index e800e53..700e6e9 100644 --- a/engine-query.md +++ b/engine-query.md @@ -27,7 +27,7 @@ use DataTables; Route::get('user-data', function() { $query = DB::table('users'); - return DataTables::queryBuilder($query)->toJson(); + return DataTables::query($query)->toJson(); }); ``` @@ -41,7 +41,7 @@ use Yajra\DataTables\DataTables; Route::get('user-data', function(DataTables $dataTables) { $query = DB::table('users'); - return $dataTables->queryBuilder($query)->toJson(); + return $dataTables->query($query)->toJson(); }); ``` @@ -53,7 +53,7 @@ use DB; Route::get('user-data', function() { $query = DB::table('users'); - return app('datatables')->queryBuilder($query)->toJson(); + return app('datatables')->query($query)->toJson(); }); ``` From b15808a73dea670ae61fec97004c3f5f61a0da42 Mon Sep 17 00:00:00 2001 From: Diogo Cerqueira <56158927+diogorcerqueira@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:34:18 +0000 Subject: [PATCH 72/78] Update installation.md --- installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation.md b/installation.md index bd054b2..7979009 100644 --- a/installation.md +++ b/installation.md @@ -28,7 +28,7 @@ composer require yajra/laravel-datatables-oracle:"^11.0" If you use most of the DataTables plugins like Buttons & HTML, you can use the all-in-one installer package. ```bash -composer require yajra/laravel-datatables:^11.0 +composer require yajra/laravel-datatables:"^11.0" ``` From 452a3690beaedf2e0fe83d4e81cee4d56831bacf Mon Sep 17 00:00:00 2001 From: haroon-mahmood-4276 Date: Thu, 27 Feb 2025 11:23:38 +0500 Subject: [PATCH 73/78] patch-1: Docs updated for Laravel v12 --- buttons-installation.md | 6 +++--- editor-installation.md | 4 +++- fractal-installation.md | 4 +++- html-installation.md | 4 +++- installation.md | 10 +++++----- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/buttons-installation.md b/buttons-installation.md index 45129b3..b6aec3e 100644 --- a/buttons-installation.md +++ b/buttons-installation.md @@ -7,8 +7,8 @@ A Laravel DataTables plugin for handling server-side exporting of table as csv, Run the following command in your project to get the latest version of the plugin: -```shell -composer require yajra/laravel-datatables-buttons:^11.0 +```bash +composer require yajra/laravel-datatables-buttons:"^12.0" ``` @@ -28,6 +28,6 @@ Open the file ```config/app.php``` and then add following service provider. After completing the step above, use the following command to publish configuration & assets: -```shell +```bash php artisan vendor:publish --tag=datatables-buttons ``` diff --git a/editor-installation.md b/editor-installation.md index 8418b18..7bed304 100644 --- a/editor-installation.md +++ b/editor-installation.md @@ -11,7 +11,9 @@ A [premium license](https://editor.datatables.net/purchase/index) is required to Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-editor:^11.0` +```bash +composer require yajra/laravel-datatables-editor:"^12.0" +``` ## Configuration diff --git a/fractal-installation.md b/fractal-installation.md index 6b53643..e717b4d 100644 --- a/fractal-installation.md +++ b/fractal-installation.md @@ -4,7 +4,9 @@ Github: https://github.com/yajra/laravel-datatables-fractal Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-fractal:^11.0` +```bash +composer require yajra/laravel-datatables-fractal:"^12.0" +``` ## Configuration > This step is optional if you are using Laravel 5.5 diff --git a/html-installation.md b/html-installation.md index 45a3f70..534ac95 100644 --- a/html-installation.md +++ b/html-installation.md @@ -6,7 +6,9 @@ Github: https://github.com/yajra/laravel-datatables-html Run the following command in your project to get the latest version of the plugin: -`composer require yajra/laravel-datatables-html:^11.0` +```bash +composer require yajra/laravel-datatables-html:"^12.0" +``` ## Configuration diff --git a/installation.md b/installation.md index dd7a8dd..9a6144d 100644 --- a/installation.md +++ b/installation.md @@ -11,7 +11,7 @@ ### Requirements -- [Laravel 11](https://github.com/laravel/framework) +- [Laravel 12](https://github.com/laravel/framework) - [jQuery DataTables v1.10.x](http://datatables.net/) @@ -22,20 +22,20 @@ 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:"^11.0" +composer require yajra/laravel-datatables-oracle:"^12.0" ``` If you are using most of the DataTables plugins like Buttons & Html, you can alternatively use the all-in-one installer package. ```bash -composer require yajra/laravel-datatables:^11.0 +composer require yajra/laravel-datatables:"^12.0" ``` ### Configuration > This step is optional if you are using Laravel 5.5+ -Open the file ```config/app.php``` or ```bootstrap/providers.php``` for Laravel 11 then add following service provider. +Open the file ```config/app.php``` or ```bootstrap/providers.php``` for Laravel 12 then add following service provider. ```php 'providers' => [ @@ -46,7 +46,7 @@ Open the file ```config/app.php``` or ```bootstrap/providers.php``` for Laravel After completing the step above, use the following command to publish configuration & assets: -``` +```bash php artisan vendor:publish --tag=datatables ``` From 2facaab955fe52f5c161ce0bd5d366d8e16d0a0a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 5 Mar 2025 10:23:17 +0800 Subject: [PATCH 74/78] docs: v12 --- exports-installation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exports-installation.md b/exports-installation.md index 79dd9fa..59afb4e 100644 --- a/exports-installation.md +++ b/exports-installation.md @@ -7,7 +7,7 @@ This package is a plugin of Laravel DataTables for handling server-side exportin ## Quick Installation ``` -composer require yajra/laravel-datatables-export -W +composer require yajra/laravel-datatables-export:"^12.0" ``` The package also requires batch job: @@ -27,4 +27,4 @@ Yajra\DataTables\ExportServiceProvider::class ``` $ php artisan vendor:publish --tag=datatables-export --force -``` \ No newline at end of file +``` From 1b426436a6038b8e2c7ba565dd54b9a213ae44b1 Mon Sep 17 00:00:00 2001 From: Romero Sarmiento Date: Wed, 1 Oct 2025 15:45:34 +0800 Subject: [PATCH 75/78] fix: Use facade --- add-column.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/add-column.md b/add-column.md index d5b984c..55191fd 100644 --- a/add-column.md +++ b/add-column.md @@ -8,7 +8,7 @@ You can add a custom column to your response by using the `addColumn` api. ## Add Column with Blade Syntax ```php -use DataTables; +use Yajra\DataTables\Facades\DataTables; Route::get('user-data', function() { $model = App\User::query(); @@ -23,7 +23,7 @@ Route::get('user-data', function() { ## Add Column with Closure ```php -use DataTables; +use Yajra\DataTables\Facades\DataTables; Route::get('user-data', function() { $model = App\User::query(); @@ -42,7 +42,7 @@ Route::get('user-data', function() { > {tip} You can use view to render your added column by passing the view path as the second argument on `addColumn` api. ```php -use DataTables; +use Yajra\DataTables\Facades\DataTables; Route::get('user-data', function() { $model = App\User::query(); @@ -64,7 +64,7 @@ Hi {{ $name }}! > {tip} Just pass the column order as the third argument of `addColumn` api. ```php -use DataTables; +use Yajra\DataTables\Facades\DataTables; Route::get('user-data', function() { $model = App\User::query(); From 595c9e880ab0c455738d153fc1adaa8f9242b349 Mon Sep 17 00:00:00 2001 From: Romero Sarmiento Date: Wed, 1 Oct 2025 16:01:33 +0800 Subject: [PATCH 76/78] fix: add 'use route' and update to facade --- html-builder-table.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/html-builder-table.md b/html-builder-table.md index 285a6da..ed75ea0 100644 --- a/html-builder-table.md +++ b/html-builder-table.md @@ -8,7 +8,8 @@ Table api accepts two parameters: `$builder->table(array $attributes, $footer = ## Table Example with Footer ```php -use DataTables; +use Illuminate\Support\Facades\Route; +use Yajra\DataTables\Facades\DataTables; use Yajra\DataTables\Html\Builder; Route::get('users', function(Builder $builder) { From 946e8187fc9b85824aa446fdb3051b657533557e Mon Sep 17 00:00:00 2001 From: Romero Sarmiento Date: Wed, 1 Oct 2025 17:15:54 +0800 Subject: [PATCH 77/78] fix: update documentation by adding use User and DB --- filter-column.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/filter-column.md b/filter-column.md index a0e9f88..2fd0b5d 100644 --- a/filter-column.md +++ b/filter-column.md @@ -5,10 +5,11 @@ To achieve this, you can use `filterColumn` api. ```php use DataTables; -use DB; +use Illuminate\Support\Facades\DB; +use App\User; Route::get('user-data', function() { - $model = App\User::select([ + $model = User::query()->select([ 'id', DB::raw("CONCAT(users.first_name,'-',users.last_name) as fullname"), 'email', From 4416fa191189e5d39acb530def619547f550adce Mon Sep 17 00:00:00 2001 From: Romero Sarmiento Date: Wed, 1 Oct 2025 17:20:20 +0800 Subject: [PATCH 78/78] fix: update sample code by using Facades --- filter-column.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filter-column.md b/filter-column.md index 2fd0b5d..81e4734 100644 --- a/filter-column.md +++ b/filter-column.md @@ -4,7 +4,7 @@ In some cases, we need to implement a custom search for a specific column. To achieve this, you can use `filterColumn` api. ```php -use DataTables; +use Yajra\DataTables\Facades\DataTables; use Illuminate\Support\Facades\DB; use App\User;