Skip to content

Commit

Permalink
[6.x] Feature: Column Custom Queries (#1654)
Browse files Browse the repository at this point in the history
* 1646 fix updated search with custom page name (#1652)

* Update datatable.php (#1653)

* wip

* Merge 5.x

---------

Co-authored-by: Sven Längler <[email protected]>
Co-authored-by: Luca Longo <[email protected]>
  • Loading branch information
3 people authored Aug 23, 2024
1 parent 02c6357 commit 1f4365c
Show file tree
Hide file tree
Showing 27 changed files with 500 additions and 479 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"larastan/larastan": "^2.9.8",
"pestphp/pest": "^2.35.0",
"orchestra/testbench": "^9.2",
"laradumps/laradumps": "^3.1.5",
"laradumps/laradumps": "^3.1",
"laravel/scout": "^10.11.1",
"openspout/openspout": "^4.24.5"
},
Expand Down
18 changes: 9 additions & 9 deletions resources/lang/it/datatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
return [
'buttons' => [
'filter' => 'Filtra',
'clear_all_filters' => 'Clear all',
'clear_all_filters' => 'Svuota filtri',
],
'labels' => [
'action' => 'Azioni',
Expand Down Expand Up @@ -55,21 +55,21 @@
'completed' => 'Esportazione completata! I tuoi file sono pronti per il download',
],
'soft_deletes' => [
'message_with_trashed' => 'Displaying all records, including deleted ones.',
'message_only_trashed' => 'Displaying only deleted records.',
'without_trashed' => 'Without deleted',
'with_trashed' => 'With deleted',
'only_trashed' => 'Only deleted',
'message_with_trashed' => 'Visualizza tutti i risultati, includendo quelli eliminati.',
'message_only_trashed' => 'Visualizza solo i risultati eliminati.',
'without_trashed' => 'Senza eliminati',
'with_trashed' => 'Con eliminati',
'only_trashed' => 'Solo eliminati',
],
'multi_sort' => [
'message' => 'Multiple sort is active',
'message' => 'E\' attivo l\'ordinamento multiplo',
],
'buttons_macros' => [
'confirm' => [
'message' => 'Are you sure you want to perform this action?',
'message' => 'Si è sicuri di voler eseguire questa azione?',
],
'confirm_prompt' => [
'message' => "Are you sure you want to perform this action? \n\n Enter :confirmValue to confirm.",
'message' => "Si è sicuri di voler eseguire questa azione? \n\n Scrivi :confirmValue per confermare.",
],
],
];
35 changes: 20 additions & 15 deletions resources/views/components/cols.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
$isFixedOnResponsive = true;
}
if (data_get($column, 'isAction') &&
if (
data_get($column, 'isAction') &&
in_array(
\PowerComponents\LivewirePowerGrid\Components\SetUp\Responsive::ACTIONS_COLUMN_NAME,
data_get($this->setUp, 'responsive.fixedColumns')
)) {
\PowerComponents\LivewirePowerGrid\Components\SetUp\Responsive::ACTIONS_COLUMN_NAME,
data_get($this->setUp, 'responsive.fixedColumns'),
)
) {
$isFixedOnResponsive = true;
}
Expand All @@ -33,24 +35,27 @@
: null;
@endphp
<th
x-data="{ sortable: @js(data_get($column, 'sortable')) }"
@if ($sortOrder) sort_order="{{ $sortOrder }}" @endif
class="{{ theme_style($theme, 'table.header.th') . ' ' . data_get($column, 'headerClass') }}"
@if ($isFixedOnResponsive) fixed @endif
@if (data_get($column, 'sortable')) x-multisort-shift-click="{{ $this->getId() }}"
x-data="{ sortable: @js(data_get($column, 'sortable')) }"
@if ($sortOrder) sort_order="{{ $sortOrder }}" @endif
class="{{ theme_style($theme, 'table.header.th') . ' ' . data_get($column, 'headerClass') }}"
@if ($isFixedOnResponsive) fixed @endif
@if (data_get($column, 'enableSort')) x-multisort-shift-click="{{ $this->getId() }}"
wire:click="sortBy('{{ $field }}')" @endif
style="{{ data_get($column, 'hidden') === true ? 'display:none' : '' }}; width: max-content; @if (data_get($column, 'sortable')) cursor:pointer; @endif {{ theme_style($theme, 'table.header.th.1') . ' ' . data_get($column, 'headerStyle') }}"
style="{{ data_get($column, 'hidden') === true ? 'display:none' : '' }}; width: max-content; @if (data_get($column, 'enableSort')) cursor:pointer; @endif {{ theme_style($theme, 'table.header.th.1') . ' ' . data_get($column, 'headerStyle') }}"
>
<div
@class(['flex gap-2' => !isBootstrap5(), theme_style($theme, 'cols.div')])
style="{{ theme_style($theme, 'cols.div.1') }}"
@class([
'flex gap-2' => !isBootstrap5(),
theme_style($theme, 'cols.div'),
])
style="{{ theme_style($theme, 'cols.div.1') }}"
>
<span data-value>{!! data_get($column, 'title') !!}</span>

@if (data_get($column, 'sortable'))
@if (data_get($column, 'enableSort'))
<x-dynamic-component
component="{{ $this->sortIcon($field) }}"
width="16"
component="{{ $this->sortIcon($field) }}"
width="16"
/>
@endif
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'attribute' => $row->{$checkboxAttribute},
])

@foreach ($columns as $column)
@foreach ($this->visibleColumns as $column)
@php
$field = data_get($column, 'field');
$content = $row->{$field} ?? '';
Expand Down
22 changes: 14 additions & 8 deletions src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

use Illuminate\Support\Traits\Macroable;

/**
* Macros
* @method static naturalSort()
* @method static searchableRaw(string $sql)
* @method static searchableJson(string $tableName) // sqlite, mysql
*/
final class Column implements \Livewire\Wireable
{
use Macroable;
Expand All @@ -18,20 +24,22 @@ final class Column implements \Livewire\Wireable

public bool $searchable = false;

public bool $enableSort = false;

public bool $hidden = false;

public bool $forceHidden = false;

public ?bool $visibleInExport = null;

public string $searchableRaw = '';

public bool $sortable = false;

public bool $index = false;

public array $properties = [];

public array $rawQueries = [];

public bool $isAction = false;

public bool $fixedOnResponsive = false;
Expand Down Expand Up @@ -144,13 +152,9 @@ public function searchable(): Column
return $this;
}

/**
* Makes the column searchable with SQL Raw
*
*/
public function searchableRaw(string $sql): Column
public function enableSort(): Column
{
$this->searchableRaw = $sql;
$this->enableSort = true;

return $this;
}
Expand All @@ -162,6 +166,8 @@ public function searchableRaw(string $sql): Column
*/
public function sortable(): Column
{
$this->enableSort();

$this->sortable = true;

return $this;
Expand Down
51 changes: 0 additions & 51 deletions src/Components/SetUp/Start.php

This file was deleted.

4 changes: 0 additions & 4 deletions src/Concerns/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ trait Base

public bool $measurePerformance = false;

public function start(): void
{
}

public function fields(): PowerGridFields
{
return PowerGrid::fields();
Expand Down
4 changes: 1 addition & 3 deletions src/Concerns/Sorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ trait Sorting

public string $sortDirection = 'asc';

public bool $withSortStringNumber = false;

public bool $multiSort = false;

public array $sortArray = [];
Expand Down Expand Up @@ -89,7 +87,7 @@ public function applySortingArray(Collection $query): Collection
public function getLabelFromColumn(string $field): string
{
$filter = collect($this->columns)->filter(
fn (Column|\stdClass $column) => $column->dataField == $field
fn (Column|\stdClass|array $column) => data_get($column, 'dataField') == $field
)->map(fn ($column) => (array) $column)
->first();

Expand Down
Loading

0 comments on commit 1f4365c

Please sign in to comment.