diff --git a/documentation.md b/documentation.md index 14788f5..5397f22 100644 --- a/documentation.md +++ b/documentation.md @@ -53,6 +53,7 @@ - [Smart Search](/docs/{{package}}/{{version}}/smart-search) - [Starts With Search](/docs/{{package}}/{{version}}/starts-with-search) - [Relationships](/docs/{{package}}/{{version}}/relationships) + - [Scout Search](/docs/{{package}}/{{version}}/scout-search) - ## Sorting/Ordering - [Manual Order](/docs/{{package}}/{{version}}/manual-order) @@ -92,6 +93,7 @@ - [Add Action](/docs/{{package}}/{{version}}/html-builder-action) - [Add Checkbox](/docs/{{package}}/{{version}}/html-builder-checkbox) - [Add Index](/docs/{{package}}/{{version}}/html-builder-index) + - [Additional Scripts](/docs/{{package}}/{{version}}/html-builder-additional-scripts) - [Github](https://github.com/yajra/laravel-datatables-html) - ## Buttons diff --git a/html-builder-additional-scripts.md b/html-builder-additional-scripts.md new file mode 100644 index 0000000..c8a4dc1 --- /dev/null +++ b/html-builder-additional-scripts.md @@ -0,0 +1,24 @@ +# Additional JavaScript Scripts + +## General Usage + +Starting with v10.10.0, you can easily add additional JavaScript scripts as blade views in your `html` function like this: + +```php +return $this->builder() + ->addScript('your.view.name'); +``` + +## Built-in Additional Scripts + +### Scout Search + +**View:** `datatables::scout` + +Control visibility of sort icons on the frontend table. Hide sort icons when Scout Search is successful (indicating fixed ordering by search relevance) and show them again when the search keyword is removed. + +### Batch Remove Optimization + +**View:** `datatables::functions.batch_remove` + +Delete all unnecessary information before sending `remove` requests (Editor), keeping only the `DT_RowId`. Otherwise, batch remove requests may fail because of server limits. diff --git a/scout-search.md b/scout-search.md new file mode 100644 index 0000000..5df30bb --- /dev/null +++ b/scout-search.md @@ -0,0 +1,56 @@ +# Scout Search + +**Note:** This documentation is applicable from version 10.11.0 and upwards, where external search engines can be integrated with Laravel Scout, replacing the built-in search functionality. + +Scout Search provides a fallback mechanism, so the built-in search will be used if any issues occur with the external search engines (e.g., server problems or indexing problems). + +Supported drivers: Meilisearch, Algolia + + + +## Setup + +To start using Scout Search, you need to install and configure Laravel Scout with your preferred driver. + +Once Laravel Scout is set up, you can enable Scout Search in your `dataTable` function like this: + +```php +return (new EloquentDataTable($query)) + // Enable scout search for eloquent model + ->enableScoutSearch(Product::class) + + // Add filters to scout search + ->scoutFilter(function (string $keyword) { + return 'region IN ["Germany", "France"]'; // Meilisearch + // or + return 'region:Germany OR region:France'; // Algolia + }) + + // Add filters to default search + ->filter(function (QueryBuilder $query, bool $scout_searched) { + if (!$scout_searched) + { + // Filter already added for scout search + $query->whereIn('region', ['Germany', 'France']); + } + + // Stock is not indexed so it has to be filtered after the initial scout search + $query->where('stock', '>', 50); + }, true); +``` + + + +## Additional JS script + +To control the visibility of sort icons on the frontend table, you'll need an additional JavaScript script. This script hides the sort icons when Scout Search is successful (indicating fixed ordering by search relevance) and shows them again when the search keyword is removed. + +If you are using the `laravel-datatables-html` package, you can easily include the script in your `html` function: + +```php +return $this->builder() + ->setTableId('products-table') + ->addScript('datatables::scout'); +``` + +Alternatively, you can manually fetch and include the JavaScript script into your own code from this file: resources/views/scout.blade.php