Skip to content

Commit 14c0725

Browse files
authored
Merge pull request #448 from rappasoft/develop
v1.14.0
2 parents ffd23f4 + 1f60eb0 commit 14c0725

File tree

10 files changed

+101
-3
lines changed

10 files changed

+101
-3
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7+
## [1.14.0] - 2021-08-31
8+
9+
### Added
10+
11+
- Added [ID language file](https://github.com/rappasoft/laravel-livewire-tables/pull/444)
12+
- Added [ability to preselect columns](https://github.com/rappasoft/laravel-livewire-tables/pull/436)
13+
- Added ability to turn off column session
14+
- [Support virtual columns](https://github.com/rappasoft/laravel-livewire-tables/pull/447)
15+
- Added ability to dump filters above table for debugging
16+
717
## [1.13.0] - 2021-08-24
818

919
### Added
@@ -446,7 +456,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
446456

447457
- Initial release
448458

449-
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.13.0...development
459+
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.14.0...development
460+
[1.14.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.13.0...v1.14.0
450461
[1.13.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.12.0...v1.13.0
451462
[1.12.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.11.0...v1.12.0
452463
[1.11.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.10.4...v1.11.0

resources/lang/id.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"All": "Semua",
3+
"Applied Filters": "Filter Diterapkan",
4+
"Applied Sorting": "Penyortiran Diterapkan",
5+
"Bulk Actions": "Aksi",
6+
"Clear": "Bersihkan",
7+
"Columns": "Kolom",
8+
"Done Reordering": "Selesai Mengurutkan Ulang",
9+
"Filters": "Filter",
10+
"Remove filter option": "Hapus opsi filter",
11+
"Remove sort option": "Hapus opsi pengurutan",
12+
"Search": "Cari",
13+
"Select All": "Pilih Semua",
14+
"Showing": "Menampilkan",
15+
"Unselect All": "Batalkan Semua Pilihan",
16+
"You are currently selecting all": "Anda sedang memilih semua",
17+
"You are not connected to the internet.": "Anda sedang tidak terhubung ke internet.",
18+
"You have selected": "Anda telah memilih",
19+
"of": "dari",
20+
"Reorder": "Urutkan ulang",
21+
"results": "hasil",
22+
"rows": "baris",
23+
"rows, do you want to select all": "baris, apakah Anda ingin memilih semua?",
24+
"No items found. Try to broaden your search.": "Tidak ada data yang ditemukan. Cobalah untuk memperluas pencarian Anda.",
25+
"to": "ke"
26+
}

resources/views/bootstrap-4/datatable.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@endif
1414
class="container-fluid p-0"
1515
>
16+
@include('livewire-tables::includes.debug')
1617
@include('livewire-tables::bootstrap-4.includes.offline')
1718
@include('livewire-tables::bootstrap-4.includes.sorting-pills')
1819
@include('livewire-tables::bootstrap-4.includes.filter-pills')

resources/views/bootstrap-5/datatable.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@endif
1414
class="container-fluid p-0"
1515
>
16+
@include('livewire-tables::includes.debug')
1617
@include('livewire-tables::bootstrap-5.includes.offline')
1718
@include('livewire-tables::bootstrap-5.includes.sorting-pills')
1819
@include('livewire-tables::bootstrap-5.includes.filter-pills')
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
@if ($dumpFilters)
3+
@dump($filters)
4+
@endif
5+
</div>

resources/views/tailwind/datatable.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@endif
1313
@endif
1414
>
15+
@include('livewire-tables::includes.debug')
1516
@include('livewire-tables::tailwind.includes.offline')
1617

1718
<div class="flex-col">

src/DataTableComponent.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ abstract class DataTableComponent extends Component
3030
use WithSearch;
3131
use WithSorting;
3232

33+
/**
34+
* Dump the filters array for debugging at the top of the datatable
35+
*
36+
* @var bool
37+
*/
38+
public bool $dumpFilters = false;
39+
3340
/**
3441
* The default pagination theme.
3542
*

src/Traits/WithColumnSelect.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,34 @@ trait WithColumnSelect
1111
{
1212
public bool $columnSelect = false;
1313
public array $columnSelectEnabled = [];
14+
public bool $usesSelect = false;
15+
public bool $rememberColumnSelection = true;
1416

1517
public function mountWithColumnSelect(): void
1618
{
19+
if (! $this->rememberColumnSelection) {
20+
$this->forgetColumnSelectSession();
21+
}
22+
1723
// If the column select is off, make sure to clear the session
1824
if (! $this->columnSelect && session()->has($this->getColumnSelectSessionKey())) {
1925
session()->forget($this->getColumnSelectSessionKey());
2026
}
2127

28+
// If any of the columns are user selected
29+
if (collect($this->columns())->filter(fn ($column) => $column->isSelected())->count() > 0) {
30+
$this->usesSelect = true;
31+
}
32+
2233
// Get a list of visible default columns that are not excluded
2334
$columns = collect($this->columns())
24-
->filter(fn ($column) => $column->isVisible() && $column->isSelectable())
35+
->filter(function ($column) {
36+
if ($this->usesSelect) {
37+
return $column->isVisible() && $column->isSelectable() && $column->isSelected();
38+
}
39+
40+
return $column->isVisible() && $column->isSelectable();
41+
})
2542
->map(fn ($column) => $column->column())
2643
->values()
2744
->toArray();
@@ -48,6 +65,11 @@ public function isColumnSelectEnabled($column): bool
4865
return in_array($column instanceof Column ? $column->column() : $column, $this->columnSelectEnabled, true);
4966
}
5067

68+
private function forgetColumnSelectSession(): void
69+
{
70+
session()->forget($this->getColumnSelectSessionKey());
71+
}
72+
5173
private function getColumnSelectSessionKey(): string
5274
{
5375
return $this->tableName.'-columnSelectEnabled';

src/Traits/WithFilters.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DateTime;
66
use Illuminate\Database\Eloquent\Builder;
77
use Illuminate\Database\Eloquent\Relations\Relation;
8+
use Illuminate\Support\Facades\Schema;
89
use Rappasoft\LaravelLivewireTables\Utilities\ColumnUtilities;
910
use Rappasoft\LaravelLivewireTables\Views\Column;
1011
use Rappasoft\LaravelLivewireTables\Views\Filter;
@@ -316,7 +317,7 @@ public function applySearchFilter($query)
316317

317318
// TODO: Skip Aggregates
318319
if (! $hasRelation) {
319-
$whereColumn = $query->getModel()->getTable() . '.' . $whereColumn;
320+
$whereColumn = Schema::hasColumn($query->getModel()->getTable(), $whereColumn) ? $query->getModel()->getTable() . '.' . $whereColumn : $whereColumn;
320321
}
321322

322323
// We can use a simple where clause

src/Views/Column.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ class Column
7474
*/
7575
public bool $selectable = true;
7676

77+
/**
78+
* @var bool
79+
*/
80+
public bool $selected = false;
81+
7782
/**
7883
* Column constructor.
7984
*
@@ -335,4 +340,22 @@ public function isSelectable(): bool
335340
{
336341
return $this->selectable === true;
337342
}
343+
344+
/**
345+
* @return $this
346+
*/
347+
public function selected(): self
348+
{
349+
$this->selected = true;
350+
351+
return $this;
352+
}
353+
354+
/**
355+
* @return bool
356+
*/
357+
public function isSelected(): bool
358+
{
359+
return $this->selected;
360+
}
338361
}

0 commit comments

Comments
 (0)