Skip to content

Commit c6ff6fb

Browse files
committed
Fix searchPanes plugin with tests
1 parent cb5bffe commit c6ff6fb

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/Html/Options/Plugins/SearchPanes.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ trait SearchPanes
1616
/**
1717
* Set searchPane option value.
1818
*
19-
* @param bool|array $value
19+
* @param array|bool|callable $value
2020
* @return $this
2121
* @see https://datatables.net/reference/option/searchPanes
2222
*/
23-
public function searchPanes(bool|array $value = true): static
23+
public function searchPanes(array|Arrayable|bool|callable $value = true): static
2424
{
2525
if (is_callable($value)) {
2626
$value = app()->call($value);
@@ -38,4 +38,17 @@ public function searchPanes(bool|array $value = true): static
3838

3939
return $this;
4040
}
41+
42+
/**
43+
* @param string|null $key
44+
* @return mixed
45+
*/
46+
public function getSearchPanes(string $key = null): mixed
47+
{
48+
if (is_null($key)) {
49+
return $this->attributes['searchPanes'] ?? true;
50+
}
51+
52+
return $this->attributes['searchPanes'][$key] ?? false;
53+
}
4154
}

tests/BuilderOptionsPluginsTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Yajra\DataTables\Html\Tests;
44

55
use Yajra\DataTables\Html\Button;
6+
use Yajra\DataTables\Html\SearchPane;
67

78
class BuilderOptionsPluginsTest extends TestCase
89
{
@@ -255,5 +256,27 @@ public function it_has_scroller_plugin()
255256
$this->assertEquals(200, $builder->getScroller('serverWait'));
256257
}
257258

259+
/** @test */
260+
public function it_has_search_panes_plugin()
261+
{
262+
$builder = $this->getHtmlBuilder();
263+
$builder->searchPanes();
264+
265+
$this->assertEquals(['show' => true], $builder->getAttribute('searchPanes'));
266+
$this->assertIsArray($builder->getSearchPanes());
258267

268+
$builder->searchPanes(false);
269+
$this->assertEquals(['show' => false], $builder->getAttribute('searchPanes'));
270+
271+
$builder->searchPanes(['hide' => true]);
272+
$this->assertEquals(['hide' => true], $builder->getAttribute('searchPanes'));
273+
274+
$builder->searchPanes(function () {
275+
return ['show' => true];
276+
});
277+
$this->assertEquals(['show' => true], $builder->getAttribute('searchPanes'));
278+
279+
$builder->searchPanes(SearchPane::make()->show()->cascadePanes());
280+
$this->assertEquals(['show' => true, 'cascadePanes' => true], $builder->getAttribute('searchPanes'));
281+
}
259282
}

0 commit comments

Comments
 (0)