8
8
use Rappasoft \LaravelLivewireTables \Exceptions \DataTableConfigurationException ;
9
9
use Rappasoft \LaravelLivewireTables \Views \Column ;
10
10
use Rappasoft \LaravelLivewireTables \Views \Columns \LinkColumn ;
11
+ use Rappasoft \LaravelLivewireTables \Views \Filters \SelectFilter ;
11
12
12
13
trait ColumnHelpers
13
14
{
@@ -438,9 +439,9 @@ public function hasSecondaryHeaderCallback(): bool
438
439
}
439
440
440
441
/**
441
- * @return callable|null
442
+ * @return mixed
442
443
*/
443
- public function getSecondaryHeaderCallback (): ? callable
444
+ public function getSecondaryHeaderCallback ()
444
445
{
445
446
return $ this ->secondaryHeaderCallback ;
446
447
}
@@ -453,10 +454,16 @@ public function getSecondaryHeaderContents($rows)
453
454
$ value = null ;
454
455
455
456
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. ' );
460
467
}
461
468
}
462
469
@@ -480,9 +487,9 @@ public function hasFooterCallback(): bool
480
487
}
481
488
482
489
/**
483
- * @return callable|null
490
+ * @return mixed
484
491
*/
485
- public function getFooterCallback (): ? callable
492
+ public function getFooterCallback ()
486
493
{
487
494
return $ this ->footerCallback ;
488
495
}
@@ -495,10 +502,16 @@ public function getFooterContents($rows)
495
502
$ value = null ;
496
503
497
504
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. ' );
502
515
}
503
516
}
504
517
0 commit comments