diff --git a/README.md b/README.md
index 283bcc8..dce2d2d 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,12 @@ Ginkelsoft DataTables is a flexible and easy-to-use package for managing tabular
php artisan vendor:publish --provider="Ginkelsoft\\DataTables\\DataTableServiceProvider" --tag=views
```
+3. **Publish configuration file** (optional) for customization:
+
+ ```bash
+ php artisan vendor:publish --provider="Ginkelsoft\DataTables\Providers\GinkelsoftDataTableServiceProvider" --tag=config
+ ```
+
---
## Usage With Livewire
diff --git a/config/datatable.php b/config/datatable.php
new file mode 100644
index 0000000..8dd59dd
--- /dev/null
+++ b/config/datatable.php
@@ -0,0 +1,47 @@
+ [
+ 'active' => true,
+ 'options' => [10, 25, 50, 100],
+ 'default' => 10,
+ ],
+
+ 'sort' => [
+ 'active' => true,
+ 'column' => 'id',
+ 'direction' => 'asc',
+ ],
+
+ 'columns' => [
+ 'hidden' => [],
+ ],
+
+ 'filters' => [
+ 'active' => true,
+ ],
+
+ 'row_actions' => [
+ 'view' => 'datatable::row-actions',
+ ],
+
+ 'bulk_actions' => [
+ 'active' => true,
+ ],
+
+ 'search' => [
+ 'active' => true,
+ ],
+
+];
diff --git a/resources/views/vendor/datatables/components/page-result.blade.php b/resources/views/vendor/datatables/components/page-result.blade.php
index 44bf63c..7b0c40d 100644
--- a/resources/views/vendor/datatables/components/page-result.blade.php
+++ b/resources/views/vendor/datatables/components/page-result.blade.php
@@ -1,10 +1,9 @@
diff --git a/resources/views/vendor/datatables/components/table.blade.php b/resources/views/vendor/datatables/components/table.blade.php
index e2a643f..b21d9bb 100644
--- a/resources/views/vendor/datatables/components/table.blade.php
+++ b/resources/views/vendor/datatables/components/table.blade.php
@@ -2,7 +2,7 @@
- @if (count($bulkActions) > 0)
+ @if (config('datatable.bulk_actions.active') && count($bulkActions) > 0)
|
@@ -36,7 +36,7 @@ class="h-5 w-5 text-blue-500 border-gray-300 rounded focus:ring-2 focus:ring-blu
@foreach($rows as $row)
|
- @if (count($bulkActions) > 0)
+ @if (config('datatable.bulk_actions.active') && count($bulkActions) > 0)
|
+ @if (config('datatable.search.active'))
@includeIf('datatable::components.search')
+ @endif
+
+ @if(config('datatable.per_page.active'))
@includeIf('datatable::components.page-result')
+ @endif
+ @if (config('datatable.filters.active'))
@if(!empty($filters))
@@ -24,8 +30,9 @@
@endif
+ @endif
- @if(count($selectedRows) > 0 && count($bulkActions) > 0)
+ @if(config('datatable.bulk_actions.active') && count($selectedRows) > 0 && count($bulkActions) > 0)
@includeIf('datatable::components.bulk-action')
diff --git a/src/DataTableServiceProvider.php b/src/DataTableServiceProvider.php
index 65d5354..576ef22 100644
--- a/src/DataTableServiceProvider.php
+++ b/src/DataTableServiceProvider.php
@@ -16,6 +16,7 @@ class DataTableServiceProvider extends ServiceProvider
*/
public function register(): void
{
+ $this->mergeConfigFrom(__DIR__ . '/../config/datatable.php', 'datatable');
$this->loadTranslationsFrom(__DIR__.'/../resources/lang/vendor/datatables', 'datatable');
$this->loadViewsFrom(__DIR__ . '/../resources/views/vendor/datatables', 'datatable');
}
@@ -30,6 +31,13 @@ public function register(): void
*/
public function boot(): void
{
+ $this->publishes([
+ __DIR__ . '/../config/datatable.php' => config_path('datatable.php'),
+ ], 'config');
+
+ // Merge default config if not published
+ $this->mergeConfigFrom(__DIR__ . '/../config/datatable.php', 'datatable');
+
$this->publishes([
__DIR__ . '/../resources/views' => resource_path('views/vendor/datatables'),
], 'views');
diff --git a/src/Livewire/DataTableComponent.php b/src/Livewire/DataTableComponent.php
index 4b11974..109f79f 100644
--- a/src/Livewire/DataTableComponent.php
+++ b/src/Livewire/DataTableComponent.php
@@ -92,19 +92,26 @@ public function mount(
string $rowActionView = 'datatable::row-actions',
array $hiddenColumns = [],
array $bulkActions = [],
- array $filters = []
+ array $filters = [],
+ string $sortColumn = '',
+ string $sortDirection = '',
+ string $perPage = '',
): void
{
$this->model = $model;
$this->columns = $columns;
$this->rowAction = array_map(fn($action) => $action instanceof Action ? $action->toArray() : $action, $rowActions);
- $this->rowActionView = $rowActionView;
- $this->hiddenColumns = $hiddenColumns;
+ $this->rowActionView = $rowActionView ?: config('datatable.row_actions.view');
+ $this->hiddenColumns = $hiddenColumns ?: config('datatable.columns.hidden');
$this->bulkActions = $bulkActions;
$this->filters = collect($filters)
->map(fn($filter) => FilterFactory::make($filter)->toArray())
->collapse()
->toArray();
+
+ $this->sortColumn = $sortColumn ?: config('datatable.sort.column');
+ $this->sortDirection = $sortDirection ?: config('datatable.sort.direction');
+ $this->perPage = $perPage ?: config('datatable.per_page.default');
}
/**
|