Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions html-builder-additional-scripts.md
Original file line number Diff line number Diff line change
@@ -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.
56 changes: 56 additions & 0 deletions scout-search.md
Original file line number Diff line number Diff line change
@@ -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

<a name="setup"></a>

## Setup

To start using Scout Search, you need to install and configure <a href="https://laravel.com/docs/10.x/scout#installation">Laravel Scout</a> 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);
```

<a name="additional-js"></a>

## 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: <a href="https://github.com/yajra/laravel-datatables-html/blob/master/src/resources/views/scout.blade.php">resources/views/scout.blade.php</a>