Skip to content

Commit

Permalink
Merge pull request #739 from rappasoft/develop
Browse files Browse the repository at this point in the history
v2.2.0
  • Loading branch information
rappasoft authored Apr 26, 2022
2 parents 2788f4a + 4d23d85 commit 6e30f7c
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 9 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to `laravel-livewire-tables` will be documented in this file

## [Unreleased]

## [2.2.0] - 2022-04-25

### Added

- Added space to include custom markup at the end of the component.
- Added events documentation
- Added ability to set columns as deselected by default - https://github.com/rappasoft/laravel-livewire-tables/pull/731
- Added NumberFilter - https://github.com/rappasoft/laravel-livewire-tables/pull/729
### Changed

- Fixed issue with Postgres and quotes - https://github.com/rappasoft/laravel-livewire-tables/pull/734

## [2.1.0] - 2022-04-12

### Added
Expand Down Expand Up @@ -593,7 +605,8 @@ Ground Up Rebuild

- Initial release

[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.1.0...development
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.2.0...development
[2.2.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.1.0...v2.2.0
[2.1.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.0.0...v2.1.0
[2.0.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.20.1...v2.0.0
[1.21.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.20.1...v1.21.0
Expand Down
9 changes: 9 additions & 0 deletions docs/columns/column-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ Column::make('Address', 'address.address')
->excludeFromColumnSelect(),
```

## Deselected by default

If you would like a column to be included in the column select but deselected by default, you can specify:

```php
Column::make('Address', 'address.address')
->deselected(),
```

## Available Methods

### setColumnSelectStatus
Expand Down
14 changes: 14 additions & 0 deletions docs/datatable/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Events
weight: 2
---

These are the available events on the datatable component that you can fire from your application:

### refreshDatatable

```php
$this->emit('refreshDatatable');
```

Calls `$refresh` on the component. Good for updating from external sources or as an alternative to polling.
63 changes: 63 additions & 0 deletions docs/examples/advanced-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,67 @@ class UsersTable extends DataTableComponent
}
}
}
```

**input-search.blade.php**

```html
@if (config('livewire-tables.theme') === 'tailwind')
<div class="flex rounded-md shadow-sm">
<input
wire:model.debounce="columnSearch.{{ $field }}"
placeholder="Search {{ ucfirst($field) }}"
type="text"
class="block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 dark:bg-gray-800 dark:text-white dark:border-gray-600 @if (isset($columnSearch[$field]) && strlen($columnSearch[$field])) rounded-none rounded-l-md focus:ring-0 focus:border-gray-300 @else focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md @endif"
/>

@if (isset($columnSearch[$field]) && strlen($columnSearch[$field]))
<span wire:click="$set('columnSearch.{{ $field }}', null)" class="inline-flex items-center px-3 text-gray-500 border border-l-0 border-gray-300 cursor-pointer bg-gray-50 rounded-r-md sm:text-sm dark:bg-gray-700 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600">
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</span>
@endif
</div>
@endif

@if (config('livewire-tables.theme') === 'bootstrap-4')
<div class="mb-3 mb-md-0 input-group">
<input
wire:model.debounce="columnSearch.{{ $field }}"
placeholder="Search {{ ucfirst($field) }}"
type="text"
class="form-control"
>

@if (isset($columnSearch[$field]) && strlen($columnSearch[$field]))
<div class="input-group-append">
<button wire:click="$set('columnSearch.{{ $field }}', null)" class="btn btn-outline-secondary" type="button">
<svg style="width:.75em;height:.75em" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
@endif
</div>
@endif

@if (config('livewire-tables.theme') === 'bootstrap-5')
<div class="mb-3 mb-md-0 input-group">
<input
wire:model.debounce="columnSearch.{{ $field }}"
placeholder="Search {{ ucfirst($field) }}"
type="text"
class="form-control"
>

@if (isset($columnSearch[$field]) && strlen($columnSearch[$field]))
<button wire:click="$set('columnSearch.{{ $field }}', null)" class="btn btn-outline-secondary" type="button">
<svg style="width:.75em;height:.75em" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
@endif
</div>
@endif
```
15 changes: 15 additions & 0 deletions docs/misc/custom-markup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Adding Custom Markup
weight: 3
---

If you would like to append any custom markup right before the end of the component, you may use the `customView` method and return a view.

This is good for loading extra content such as modals.

```php
public function customView(): string
{
return 'includes.custom';
}
```
2 changes: 1 addition & 1 deletion docs/misc/debugging.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Debugging
weight: 3
weight: 4
---

## Configuration
Expand Down
4 changes: 4 additions & 0 deletions docs/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ New:
```php
$this->getAppliedFilterWithValue('active');
```

## Modals

`modalsView()` was changed to `customView()`
12 changes: 7 additions & 5 deletions docs/usage/creating-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ class UsersTable extends DataTableComponent

public function configure(): void
{
$this->setPrimaryKey('id')
$this->setPrimaryKey('id');
}

public function columns(): array
{
Column::make('ID', 'id')
->sortable(),
Column::make('Name')
->sortable(),
return [
Column::make('ID', 'id')
->sortable(),
Column::make('Name')
->sortable(),
];
}
}
```
Expand Down
29 changes: 29 additions & 0 deletions resources/views/components/tools/filters/number.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@php
$theme = $component->getTheme();
@endphp

@if ($theme === 'tailwind')
<div class="rounded-md shadow-sm">
<input
wire:model.stop="{{ $component->getTableName() }}.filters.{{ $filter->getKey() }}"
wire:key="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
id="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
type="number"
@if($filter->hasConfig('min')) min="{{ $filter->getConfig('min') }}" @endif
@if($filter->hasConfig('max')) max="{{ $filter->getConfig('max') }}" @endif
class="block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-800 dark:text-white dark:border-gray-600"
/>
</div>
@elseif ($theme === 'bootstrap-4' || $theme === 'bootstrap-5')
<div class="mb-3 mb-md-0 input-group">
<input
wire:model.stop="{{ $component->getTableName() }}.filters.{{ $filter->getKey() }}"
wire:key="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
id="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
type="number"
@if($filter->hasConfig('min')) min="{{ $filter->getConfig('min') }}" @endif
@if($filter->hasConfig('max')) max="{{ $filter->getConfig('max') }}" @endif
class="form-control"
/>
</div>
@endif
4 changes: 4 additions & 0 deletions resources/views/datatable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@
</x-livewire-tables::table>

<x-livewire-tables::pagination :rows="$rows" />

@isset($customView)
@include($customView)
@endisset
</x-livewire-tables::wrapper>
Empty file.
11 changes: 11 additions & 0 deletions src/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ public function builder(): Builder
throw new DataTableConfigurationException('You must either specify a model or implement the builder method.');
}

/**
* The view to add any modals for the table, could also be used for any non-visible html
*
* @return string
*/
public function customView(): string
{
return 'livewire-tables::stubs.custom';
}

/**
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
Expand All @@ -105,6 +115,7 @@ public function render()
->with([
'columns' => $this->getColumns(),
'rows' => $this->getRows(),
'customView' => $this->customView(),
]);
}
}
2 changes: 1 addition & 1 deletion src/Traits/WithColumnSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function mountWithColumnSelect(): void
// Get a list of visible default columns that are not excluded
$columns = collect($this->getColumns())
->filter(function ($column) {
return $column->isVisible() && $column->isSelectable();
return $column->isVisible() && $column->isSelectable() && $column->isSelected();
})
->map(fn ($column) => $column->getHash())
->values()
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/WithSorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function applySorting(Builder $builder): Builder
} elseif ($column->isBaseColumn()) {
$builder->orderBy($column->getColumnSelectName(), $direction);
} else {
$builder->orderByRaw('`'.$column->getColumnSelectName().'`' . ' ' . $direction);
$builder->orderByRaw('"'.$column->getColumnSelectName().'"' . ' ' . $direction);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Views/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Column
protected $labelCallback;
protected bool $hidden = false;
protected bool $selectable = true;
protected bool $selected = true;
protected bool $secondaryHeader = false;
protected $secondaryHeaderCallback;
protected bool $footer = false;
Expand Down
27 changes: 27 additions & 0 deletions src/Views/Filters/NumberFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Views\Filters;

use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Filter;

class NumberFilter extends Filter
{
public function validate($value)
{
return is_numeric($value) ? $value : false;
}

public function isEmpty($value): bool
{
return $value === '';
}

public function render(DataTableComponent $component)
{
return view('livewire-tables::components.tools.filters.number', [
'component' => $component,
'filter' => $this,
]);
}
}
10 changes: 10 additions & 0 deletions src/Views/Traits/Configuration/ColumnConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ public function excludeFromColumnSelect(): self
return $this;
}

/**
* @return $this
*/
public function deselected(): self
{
$this->selected = false;

return $this;
}

/**
* @param string $field
*
Expand Down
8 changes: 8 additions & 0 deletions src/Views/Traits/Helpers/ColumnHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ public function isSelectable(): bool
return $this->selectable === true;
}

/**
* @return bool
*/
public function isSelected(): bool
{
return $this->selected === true;
}

/**
* @return bool
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/Views/Traits/Configuration/ColumnConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,16 @@ public function can_make_column_unclickable(): void

$this->assertFalse($column->isClickable());
}

/** @test */
public function can_deselect_column(): void
{
$column = Column::make('Name');

$this->assertTrue($column->isSelected());

$column->deselected();

$this->assertFalse($column->isSelected());
}
}

0 comments on commit 6e30f7c

Please sign in to comment.