diff --git a/add-column.md b/add-column.md
index 01dcaf3..55191fd 100644
--- a/add-column.md
+++ b/add-column.md
@@ -1,12 +1,14 @@
# 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 for those columns. If you need them, use the `editColumn` api instead.
## Add Column with Blade Syntax
```php
-use DataTables;
+use Yajra\DataTables\Facades\DataTables;
Route::get('user-data', function() {
$model = App\User::query();
@@ -21,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();
@@ -40,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();
@@ -62,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();
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..089a318 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`.
@@ -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()
{
diff --git a/buttons-fast-excel.md b/buttons-fast-excel.md
new file mode 100644
index 0000000..4d0819e
--- /dev/null
+++ b/buttons-fast-excel.md
@@ -0,0 +1,62 @@
+# Fast Excel Integration
+
+[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 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
+
+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 bool $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 bool $fastExcel = true;
+ protected bool $fastExcelCallback = false;
+
+```
+
+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
+
+Just override the `fastExcelCallback` method:
+
+```php
+class UsersDataTable extends DataTable
+{
+ protected bool $fastExcel = true;
+
+ public function fastExcelCallback() \Closure
+ {
+ return function ($row) {
+ return [
+ 'Name' => $row['name'],
+ 'Email' => $row['email'],
+ ];
+ };
+ }
+
+...
+```
diff --git a/buttons-installation.md b/buttons-installation.md
index 87e80a8..b6aec3e 100644
--- a/buttons-installation.md
+++ b/buttons-installation.md
@@ -1,11 +1,20 @@
-# Buttons Plugin Installation
+# Buttons Plugin
+
+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:^3.0`
+```bash
+composer require yajra/laravel-datatables-buttons:"^12.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.
@@ -19,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:
-```
+```bash
php artisan vendor:publish --tag=datatables-buttons
```
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 cf92ae2..14788f5 100644
--- a/documentation.md
+++ b/documentation.md
@@ -2,18 +2,15 @@
- [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)
- - [Installation](/docs/{{package}}/{{version}}/installation)
- - [Demo Application](https://datatables.yajrabox.com/)
+ - [Installation](/docs/{{package}}/{{version}}/installation)
- [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)
@@ -28,8 +25,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)
@@ -41,8 +36,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)
@@ -65,6 +60,11 @@
- [Order Columns](/docs/{{package}}/{{version}}/order-columns)
- [Order By Nulls Last](/docs/{{package}}/{{version}}/order-by-nulls-last)
+- ## SearchPanes
+ - [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)
+
- ## Utilities
- [XSS filtering](/docs/{{package}}/{{version}}/xss)
- [Blacklist Columns](/docs/{{package}}/{{version}}/blacklist)
@@ -76,41 +76,54 @@
### 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)
+- ## 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)
- - [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)
+
+- ## 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)
- - [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/editor-installation.md b/editor-installation.md
index c4c95b6..7bed304 100644
--- a/editor-installation.md
+++ b/editor-installation.md
@@ -11,14 +11,16 @@ 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`
+```bash
+composer require yajra/laravel-datatables-editor:"^12.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' => [
diff --git a/editor-tutorial.md b/editor-tutorial.md
index cf453b2..caff59b 100644
--- a/editor-tutorial.md
+++ b/editor-tutorial.md
@@ -1,15 +1,11 @@
-# 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.
## Pre-requisites
-This tutorial requires https://yajrabox.com/docs/laravel-datatables/master/quick-starter.
-
-## Install DataTables Editor assets.
-
- yarn add datatables.net-editor datatables.net-editor-bs4 datatables.net-select-bs4
+This tutorial requires https://yajrabox.com/docs/laravel-datatables/10.0/quick-starter.
## Editor License
@@ -17,107 +13,162 @@ 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');
-
- require('bootstrap');
- require('datatables.net-bs4');
- require('datatables.net-buttons-bs4');
- require('datatables.net-select-bs4');
- require('datatables.net-editor-bs4');
- } catch (e) {}
+## Install DataTables Editor assets.
+```sh
+npm i datatables.net-editor datatables.net-editor-bs5
+```
-## Add editor styles on `resources/sass/app.scss`.
+## Register editor script on `resources/js/app.js`
- @import "~datatables.net-select-bs4/css/select.bootstrap4.css";
- @import "~datatables.net-editor-bs4/css/editor.bootstrap4.css";
+```js
+import './bootstrap';
+import 'laravel-datatables-vite';
-## Recompile assets.
+import "datatables.net-editor";
+import Editor from "datatables.net-editor-bs5";
+Editor(window, $);
+```
- yarn
- yarn watch / dev / prod
+## Add editor styles on `resources/sass/app.scss`.
+```css
+// Fonts
+@import url('https://fonts.bunny.net/css?family=Nunito');
-## Update UsersDataTable and register the Editor buttons.
+// Variables
+@import 'variables';
-> 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.
+// Bootstrap
+@import 'bootstrap/scss/bootstrap';
- 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($query)
+ public function dataTable(QueryBuilder $query): EloquentDataTable
{
- return datatables()
- ->eloquent($query)
- ->setRowId('id') // Set the RowID
- ...
+ return (new EloquentDataTable($query))->setRowId('id');
}
- public function html()
+ /**
+ * Get query source of dataTable.
+ *
+ * @param \App\Models\User $model
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ 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(): 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 +176,14 @@ php artisan datatables:editor Users
Edit `routes/web.php` and register the store user route.
-```
-Route::post('/users', 'UsersController@store')->name('users.store');
+```php
+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
-```
+```php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
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
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
diff --git a/engine-query.md b/engine-query.md
index 4d2c09d..700e6e9 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
@@ -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();
});
```
diff --git a/exports-installation.md b/exports-installation.md
new file mode 100644
index 0000000..59afb4e
--- /dev/null
+++ b/exports-installation.md
@@ -0,0 +1,30 @@
+# Export Plugin Installation
+
+Github: https://github.com/yajra/laravel-datatables-export
+
+This package is a plugin of Laravel DataTables for handling server-side exporting using Queue, OpenSpout and Livewire.
+
+## Quick Installation
+
+```
+composer require yajra/laravel-datatables-export:"^12.0"
+```
+
+The package also requires batch job:
+
+```
+php artisan queue:batches-table
+php artisan migrate
+```
+
+## Service Provider (Optional since Laravel 5.5+)
+
+```
+Yajra\DataTables\ExportServiceProvider::class
+```
+
+## Configuration and Assets (Optional)
+
+```
+$ php artisan vendor:publish --tag=datatables-export --force
+```
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
+