Skip to content

Commit 6b3f200

Browse files
committed
feat: layout builder
1 parent 01c89e0 commit 6b3f200

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/Html/HasOptions.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function displayStart(int $value = 0): static
7373
* Set dom option value.
7474
*
7575
* @return $this
76+
* @deprecated Use layout() method instead.
7677
*
7778
* @see https://datatables.net/reference/option/dom
7879
*/
@@ -83,6 +84,30 @@ public function dom(string $value): static
8384
return $this;
8485
}
8586

87+
/**
88+
* Set layout option value.
89+
*
90+
* @return $this
91+
*
92+
* @see https://datatables.net/reference/option/layout
93+
*/
94+
public function layout(array|Layout|callable $value): static
95+
{
96+
if ($value instanceof Layout) {
97+
$value = $value->toArray();
98+
}
99+
100+
if (is_callable($value)) {
101+
$layout = new Layout;
102+
$value($layout);
103+
$value = $layout->toArray();
104+
}
105+
106+
$this->attributes['layout'] = $value;
107+
108+
return $this;
109+
}
110+
86111
/**
87112
* Set lengthMenu option value.
88113
*

src/Html/Layout.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yajra\DataTables\Html;
6+
7+
use Illuminate\Support\Fluent;
8+
use Illuminate\Support\Traits\Macroable;
9+
10+
class Layout extends Fluent
11+
{
12+
use Macroable;
13+
14+
public function topStart(string|array|null $options, int $order = 0): static
15+
{
16+
return $this->top($options, $order, 'Start');
17+
}
18+
19+
public function topEnd(string|array|null $options, int $order = 0): static
20+
{
21+
return $this->top($options, $order, 'End');
22+
}
23+
24+
public function bottomStart(string|array|null $options, int $order = 0): static
25+
{
26+
return $this->bottom($options, $order, 'Start');
27+
}
28+
29+
public function bottomEnd(string|array|null $options, int $order = 0): static
30+
{
31+
return $this->bottom($options, $order, 'End');
32+
}
33+
34+
public function top(array|string|null $options, ?int $order = null, ?string $position = null): static
35+
{
36+
if ($order > 0) {
37+
$this->attributes["top{$order}{$position}"] = $options;
38+
} else {
39+
$this->attributes["top{$position}"] = $options;
40+
}
41+
42+
return $this;
43+
}
44+
45+
public function bottom(array|string|null $options, ?int $order = null, ?string $position = null): static
46+
{
47+
if ($order > 0) {
48+
$this->attributes["bottom{$order}{$position}"] = $options;
49+
} else {
50+
$this->attributes["bottom{$position}"] = $options;
51+
}
52+
53+
return $this;
54+
}
55+
}

0 commit comments

Comments
 (0)