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
20 changes: 19 additions & 1 deletion src/Html/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class Builder
*/
protected string|array $ajax = '';

/**
* @var array
*/
protected array $additionalScripts = [];

/**
* @param Repository $config
* @param Factory $view
Expand Down Expand Up @@ -179,7 +184,7 @@ protected function template(): string

$template = $this->template ?: $configTemplate;

return $this->view->make($template, ['editors' => $this->editors])->render();
return $this->view->make($template, ['editors' => $this->editors, 'scripts' => $this->additionalScripts])->render();
}

/**
Expand Down Expand Up @@ -291,4 +296,17 @@ public function getAjax(string $key = null): array|string

return $this->ajax;
}

/**
* Add additional scripts to the DataTables JS initialization.
*
* @param string $view
* @return $this
*/
public function addScript(string $view): static
{
$this->additionalScripts[] = $view;

return $this;
}
}
23 changes: 23 additions & 0 deletions src/resources/views/scout.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$(function(){
$('#%1$s').on('xhr.dt', function (e, settings, json, xhr) {
if (json == null || !('disableOrdering' in json)) return;

let table = {{ config('datatables-html.namespace', 'LaravelDataTables') }}[$(this).attr('id')];
if (json.disableOrdering) {
table.settings()[0].aoColumns.forEach(function(column) {
column.bSortable = false;
$(column.nTh).removeClass('sorting_asc sorting_desc sorting').addClass('sorting_disabled');
});
} else {
let changed = false;
table.settings()[0].aoColumns.forEach(function(column) {
if (column.bSortable) return;
column.bSortable = true;
changed = true;
});
if (changed) {
table.draw();
}
}
});
});
3 changes: 3 additions & 0 deletions src/resources/views/script.blade.php
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
$(function(){window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}=window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}||{};window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s"]=$("#%1$s").DataTable(%2$s);});
@foreach ($scripts as $script)
@include($script)
@endforeach