diff --git a/CHANGELOG.md b/CHANGELOG.md
index c16f88303..1fa92345a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,16 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
## [Unreleased]
+## [1.14.0] - 2021-08-31
+
+### Added
+
+- Added [ID language file](https://github.com/rappasoft/laravel-livewire-tables/pull/444)
+- Added [ability to preselect columns](https://github.com/rappasoft/laravel-livewire-tables/pull/436)
+- Added ability to turn off column session
+- [Support virtual columns](https://github.com/rappasoft/laravel-livewire-tables/pull/447)
+- Added ability to dump filters above table for debugging
+
## [1.13.0] - 2021-08-24
### Added
@@ -446,7 +456,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
- Initial release
-[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.13.0...development
+[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.14.0...development
+[1.14.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.13.0...v1.14.0
[1.13.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.12.0...v1.13.0
[1.12.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.11.0...v1.12.0
[1.11.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.4...v1.11.0
diff --git a/resources/lang/id.json b/resources/lang/id.json
new file mode 100644
index 000000000..926651112
--- /dev/null
+++ b/resources/lang/id.json
@@ -0,0 +1,26 @@
+{
+ "All": "Semua",
+ "Applied Filters": "Filter Diterapkan",
+ "Applied Sorting": "Penyortiran Diterapkan",
+ "Bulk Actions": "Aksi",
+ "Clear": "Bersihkan",
+ "Columns": "Kolom",
+ "Done Reordering": "Selesai Mengurutkan Ulang",
+ "Filters": "Filter",
+ "Remove filter option": "Hapus opsi filter",
+ "Remove sort option": "Hapus opsi pengurutan",
+ "Search": "Cari",
+ "Select All": "Pilih Semua",
+ "Showing": "Menampilkan",
+ "Unselect All": "Batalkan Semua Pilihan",
+ "You are currently selecting all": "Anda sedang memilih semua",
+ "You are not connected to the internet.": "Anda sedang tidak terhubung ke internet.",
+ "You have selected": "Anda telah memilih",
+ "of": "dari",
+ "Reorder": "Urutkan ulang",
+ "results": "hasil",
+ "rows": "baris",
+ "rows, do you want to select all": "baris, apakah Anda ingin memilih semua?",
+ "No items found. Try to broaden your search.": "Tidak ada data yang ditemukan. Cobalah untuk memperluas pencarian Anda.",
+ "to": "ke"
+}
diff --git a/resources/views/bootstrap-4/datatable.blade.php b/resources/views/bootstrap-4/datatable.blade.php
index 5b07de339..09b52ef89 100644
--- a/resources/views/bootstrap-4/datatable.blade.php
+++ b/resources/views/bootstrap-4/datatable.blade.php
@@ -13,6 +13,7 @@
@endif
class="container-fluid p-0"
>
+ @include('livewire-tables::includes.debug')
@include('livewire-tables::bootstrap-4.includes.offline')
@include('livewire-tables::bootstrap-4.includes.sorting-pills')
@include('livewire-tables::bootstrap-4.includes.filter-pills')
diff --git a/resources/views/bootstrap-5/datatable.blade.php b/resources/views/bootstrap-5/datatable.blade.php
index dbfe474ac..e632a015e 100644
--- a/resources/views/bootstrap-5/datatable.blade.php
+++ b/resources/views/bootstrap-5/datatable.blade.php
@@ -13,6 +13,7 @@
@endif
class="container-fluid p-0"
>
+ @include('livewire-tables::includes.debug')
@include('livewire-tables::bootstrap-5.includes.offline')
@include('livewire-tables::bootstrap-5.includes.sorting-pills')
@include('livewire-tables::bootstrap-5.includes.filter-pills')
diff --git a/resources/views/includes/debug.blade.php b/resources/views/includes/debug.blade.php
new file mode 100644
index 000000000..2d9678e17
--- /dev/null
+++ b/resources/views/includes/debug.blade.php
@@ -0,0 +1,5 @@
+
+ @if ($dumpFilters)
+ @dump($filters)
+ @endif
+
diff --git a/resources/views/tailwind/datatable.blade.php b/resources/views/tailwind/datatable.blade.php
index 3618e94fe..613f60733 100644
--- a/resources/views/tailwind/datatable.blade.php
+++ b/resources/views/tailwind/datatable.blade.php
@@ -12,6 +12,7 @@
@endif
@endif
>
+ @include('livewire-tables::includes.debug')
@include('livewire-tables::tailwind.includes.offline')
diff --git a/src/DataTableComponent.php b/src/DataTableComponent.php
index 9e6a332ca..49589acc7 100644
--- a/src/DataTableComponent.php
+++ b/src/DataTableComponent.php
@@ -30,6 +30,13 @@ abstract class DataTableComponent extends Component
use WithSearch;
use WithSorting;
+ /**
+ * Dump the filters array for debugging at the top of the datatable
+ *
+ * @var bool
+ */
+ public bool $dumpFilters = false;
+
/**
* The default pagination theme.
*
diff --git a/src/Traits/WithColumnSelect.php b/src/Traits/WithColumnSelect.php
index 53c7ddc23..8332c8f68 100644
--- a/src/Traits/WithColumnSelect.php
+++ b/src/Traits/WithColumnSelect.php
@@ -11,17 +11,34 @@ trait WithColumnSelect
{
public bool $columnSelect = false;
public array $columnSelectEnabled = [];
+ public bool $usesSelect = false;
+ public bool $rememberColumnSelection = true;
public function mountWithColumnSelect(): void
{
+ if (! $this->rememberColumnSelection) {
+ $this->forgetColumnSelectSession();
+ }
+
// If the column select is off, make sure to clear the session
if (! $this->columnSelect && session()->has($this->getColumnSelectSessionKey())) {
session()->forget($this->getColumnSelectSessionKey());
}
+ // If any of the columns are user selected
+ if (collect($this->columns())->filter(fn ($column) => $column->isSelected())->count() > 0) {
+ $this->usesSelect = true;
+ }
+
// Get a list of visible default columns that are not excluded
$columns = collect($this->columns())
- ->filter(fn ($column) => $column->isVisible() && $column->isSelectable())
+ ->filter(function ($column) {
+ if ($this->usesSelect) {
+ return $column->isVisible() && $column->isSelectable() && $column->isSelected();
+ }
+
+ return $column->isVisible() && $column->isSelectable();
+ })
->map(fn ($column) => $column->column())
->values()
->toArray();
@@ -48,6 +65,11 @@ public function isColumnSelectEnabled($column): bool
return in_array($column instanceof Column ? $column->column() : $column, $this->columnSelectEnabled, true);
}
+ private function forgetColumnSelectSession(): void
+ {
+ session()->forget($this->getColumnSelectSessionKey());
+ }
+
private function getColumnSelectSessionKey(): string
{
return $this->tableName.'-columnSelectEnabled';
diff --git a/src/Traits/WithFilters.php b/src/Traits/WithFilters.php
index 9b33ea655..7c7be17df 100644
--- a/src/Traits/WithFilters.php
+++ b/src/Traits/WithFilters.php
@@ -5,6 +5,7 @@
use DateTime;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
+use Illuminate\Support\Facades\Schema;
use Rappasoft\LaravelLivewireTables\Utilities\ColumnUtilities;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Filter;
@@ -316,7 +317,7 @@ public function applySearchFilter($query)
// TODO: Skip Aggregates
if (! $hasRelation) {
- $whereColumn = $query->getModel()->getTable() . '.' . $whereColumn;
+ $whereColumn = Schema::hasColumn($query->getModel()->getTable(), $whereColumn) ? $query->getModel()->getTable() . '.' . $whereColumn : $whereColumn;
}
// We can use a simple where clause
diff --git a/src/Views/Column.php b/src/Views/Column.php
index 8137ca772..29274efcc 100644
--- a/src/Views/Column.php
+++ b/src/Views/Column.php
@@ -74,6 +74,11 @@ class Column
*/
public bool $selectable = true;
+ /**
+ * @var bool
+ */
+ public bool $selected = false;
+
/**
* Column constructor.
*
@@ -335,4 +340,22 @@ public function isSelectable(): bool
{
return $this->selectable === true;
}
+
+ /**
+ * @return $this
+ */
+ public function selected(): self
+ {
+ $this->selected = true;
+
+ return $this;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isSelected(): bool
+ {
+ return $this->selected;
+ }
}