-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add IncrementColumn with RowIndex, ColumnIndex --------- Co-authored-by: lrljoe <[email protected]>
- Loading branch information
Showing
13 changed files
with
156 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: Increment Column (beta) | ||
weight: 12 | ||
--- | ||
|
||
The IncrementColumn provides an easy way to display the row's index in the loop. | ||
|
||
Please note - this is not linked to the row's primary key! | ||
|
||
```php | ||
IncrementColumn::make('#'), | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@aware(['rowIndex']) | ||
<div {{ $attributeBag }}>{{ $rowIndex+1 }}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Views\Columns; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException; | ||
use Rappasoft\LaravelLivewireTables\Views\Column; | ||
|
||
class IncrementColumn extends Column | ||
{ | ||
protected string $view = 'livewire-tables::includes.columns.increment'; | ||
|
||
public function __construct(string $title, ?string $from = null) | ||
{ | ||
parent::__construct($title, $from); | ||
$this->label(fn () => null); | ||
|
||
} | ||
|
||
public function getContents(Model $row): null|string|\Illuminate\Support\HtmlString|DataTableConfigurationException|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View | ||
{ | ||
return view($this->getView()) | ||
->withColumn($this) | ||
->withAttributeBag($this->getAttributeBag($row)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Views\Columns; | ||
|
||
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException; | ||
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet; | ||
use Rappasoft\LaravelLivewireTables\Tests\TestCase; | ||
use Rappasoft\LaravelLivewireTables\Views\Columns\IncrementColumn; | ||
|
||
final class IncrementColumnTest extends TestCase | ||
{ | ||
public function test_can_set_the_column_title(): void | ||
{ | ||
$column = IncrementColumn::make('Name', 'name'); | ||
|
||
$this->assertSame('Name', $column->getTitle()); | ||
} | ||
|
||
public function test_can_not_infer_field_name_from_title_if_no_from(): void | ||
{ | ||
$column = IncrementColumn::make('My Title'); | ||
|
||
$this->assertNull($column->getField()); | ||
} | ||
|
||
public function test_can_not_render_field_if_no_title(): void | ||
{ | ||
$this->expectException(\ArgumentCountError::class); | ||
|
||
IncrementColumn::make()->getContents(Pet::find(1)); | ||
} | ||
|
||
public function test_handles_row_index_correctly(): void | ||
{ | ||
$rows = $this->basicTable->getRows(); | ||
$row1 = $rows->first(); | ||
$col = IncrementColumn::make('#')->setRowIndex(1); | ||
$contents = $col->getContents($row1); | ||
$this->assertSame(1, $col->getRowIndex()); | ||
|
||
} | ||
|
||
public function test_handles_col_index_correctly(): void | ||
{ | ||
$rows = $this->basicTable->getRows(); | ||
$row1 = $rows->first(); | ||
$col = IncrementColumn::make('#')->setColumnIndex(2); | ||
$contents = $col->getContents($row1); | ||
$this->assertSame(2, $col->getColumnIndex()); | ||
|
||
} | ||
|
||
public function test_handles_indexes_correctly(): void | ||
{ | ||
$rows = $this->basicTable->getRows(); | ||
$row1 = $rows->first(); | ||
$col = IncrementColumn::make('#')->setIndexes(5, 3); | ||
$contents = $col->getContents($row1); | ||
$this->assertSame(5, $col->getRowIndex()); | ||
$this->assertSame(3, $col->getColumnIndex()); | ||
|
||
} | ||
|
||
public function test_renders_correctly(): void | ||
{ | ||
$rows = $this->basicTable->getRows(); | ||
$row1 = $rows->first(); | ||
$col = IncrementColumn::make('#')->setRowIndex(1); | ||
$contents = $col->getContents($row1); | ||
$this->assertSame(1, $col->getRowIndex()); | ||
|
||
} | ||
} |