Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.14.0 #448

Merged
merged 15 commits into from
Sep 5, 2021
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions resources/lang/id.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions resources/views/bootstrap-4/datatable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions resources/views/bootstrap-5/datatable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions resources/views/includes/debug.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
@if ($dumpFilters)
@dump($filters)
@endif
</div>
1 change: 1 addition & 0 deletions resources/views/tailwind/datatable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@endif
@endif
>
@include('livewire-tables::includes.debug')
@include('livewire-tables::tailwind.includes.offline')

<div class="flex-col">
Expand Down
7 changes: 7 additions & 0 deletions src/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
24 changes: 23 additions & 1 deletion src/Traits/WithColumnSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion src/Traits/WithFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/Views/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class Column
*/
public bool $selectable = true;

/**
* @var bool
*/
public bool $selected = false;

/**
* Column constructor.
*
Expand Down Expand Up @@ -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;
}
}