Skip to content

feat: Macroable DataTable Base Class #193

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

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Services/DataTable.php
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Traits\Macroable;
use Maatwebsite\Excel\ExcelServiceProvider;
use OpenSpout\Common\Entity\Style\Style;
use Rap2hpoutre\FastExcel\FastExcel;
@@ -29,6 +30,8 @@

abstract class DataTable implements DataTableButtons
{
use Macroable;

/**
* DataTables print preview view.
*
15 changes: 15 additions & 0 deletions tests/DataTableServiceTest.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
use Yajra\DataTables\Buttons\Tests\DataTables\UsersDataTable;
use Yajra\DataTables\Buttons\Tests\Models\User;
use Yajra\DataTables\EloquentDataTable;
use Yajra\DataTables\Services\DataTable;

class DataTableServiceTest extends TestCase
{
@@ -80,6 +81,20 @@ public function it_allows_response_callback(): void
$this->assertEquals(1, $response->json('recordsFiltered'));
}

#[Test]
public function it_is_macroable(): void
{
$dataTable = new class extends DataTable {};

$this->assertObjectHasProperty('macros', $dataTable);
$this->assertTrue(method_exists($dataTable, 'macro'), 'Method macro does not exist.');
$this->assertTrue(method_exists($dataTable, 'mixin'), 'Method mixin does not exist.');

DataTable::macro('macroMethod', fn () => 'macro');

$this->assertEquals('macro', $dataTable->macroMethod());
}

protected function setUp(): void
{
parent::setUp();