Skip to content

Commit e3013a7

Browse files
committed
Ability to pass select filters to secondary header and footer
1 parent a994759 commit e3013a7

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/Views/Traits/Helpers/ColumnHelpers.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
99
use Rappasoft\LaravelLivewireTables\Views\Column;
1010
use Rappasoft\LaravelLivewireTables\Views\Columns\LinkColumn;
11+
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
1112

1213
trait ColumnHelpers
1314
{
@@ -438,9 +439,9 @@ public function hasSecondaryHeaderCallback(): bool
438439
}
439440

440441
/**
441-
* @return callable|null
442+
* @return mixed
442443
*/
443-
public function getSecondaryHeaderCallback(): ?callable
444+
public function getSecondaryHeaderCallback()
444445
{
445446
return $this->secondaryHeaderCallback;
446447
}
@@ -453,10 +454,16 @@ public function getSecondaryHeaderContents($rows)
453454
$value = null;
454455

455456
if ($this->hasSecondaryHeaderCallback()) {
456-
$value = call_user_func($this->getSecondaryHeaderCallback(), $rows);
457-
458-
if ($this->isHtml()) {
459-
return new HtmlString($value);
457+
if (is_callable($this->getSecondaryHeaderCallback())) {
458+
$value = call_user_func($this->getSecondaryHeaderCallback(), $rows);
459+
460+
if ($this->isHtml()) {
461+
return new HtmlString($value);
462+
}
463+
} elseif ($this->getSecondaryHeaderCallback() instanceof SelectFilter) {
464+
return $this->getSecondaryHeaderCallback()->render($this->getComponent());
465+
} else {
466+
throw new DataTableConfigurationException('The secondary header callback must be a closure or a filter object.');
460467
}
461468
}
462469

@@ -480,9 +487,9 @@ public function hasFooterCallback(): bool
480487
}
481488

482489
/**
483-
* @return callable|null
490+
* @return mixed
484491
*/
485-
public function getFooterCallback(): ?callable
492+
public function getFooterCallback()
486493
{
487494
return $this->footerCallback;
488495
}
@@ -495,10 +502,16 @@ public function getFooterContents($rows)
495502
$value = null;
496503

497504
if ($this->hasFooterCallback()) {
498-
$value = call_user_func($this->getFooterCallback(), $rows);
499-
500-
if ($this->isHtml()) {
501-
return new HtmlString($value);
505+
if (is_callable($this->getFooterCallback())) {
506+
$value = call_user_func($this->getFooterCallback(), $rows);
507+
508+
if ($this->isHtml()) {
509+
return new HtmlString($value);
510+
}
511+
} elseif ($this->getFooterCallback() instanceof SelectFilter) {
512+
return $this->getFooterCallback()->render($this->getComponent());
513+
} else {
514+
throw new DataTableConfigurationException('The footer callback must be a closure or a filter object.');
502515
}
503516
}
504517

0 commit comments

Comments
 (0)