File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Rappasoft \LaravelLivewireTables \Views ;
4
4
5
+ use Illuminate \Support \HtmlString ;
5
6
use Illuminate \Support \Str ;
6
7
7
8
/**
@@ -89,6 +90,16 @@ class Column
89
90
*/
90
91
public $ footerCallback ;
91
92
93
+ /**
94
+ * @var
95
+ */
96
+ public $ linkCallback ;
97
+
98
+ /**
99
+ * @var ?string
100
+ */
101
+ public ?string $ linkTarget ;
102
+
92
103
/**
93
104
* Column constructor.
94
105
*
@@ -286,6 +297,15 @@ public function formatted($row, $column = null)
286
297
$ value = call_user_func ($ this ->formatCallback , $ value , $ column , $ row );
287
298
}
288
299
300
+ if ($ this ->linkCallback ) {
301
+ $ url = call_user_func ($ this ->linkCallback , $ value , $ column , $ row );
302
+
303
+ if ($ url ) {
304
+ $ linkTarget = $ this ->linkTarget ? "target=' $ this ->linkTarget ' " : '' ;
305
+ $ value = new HtmlString ("<a href=' $ url' $ linkTarget> $ value</a> " );
306
+ }
307
+ }
308
+
289
309
return $ value ;
290
310
}
291
311
@@ -412,4 +432,18 @@ public function footerFormatted($rows)
412
432
413
433
return $ value ;
414
434
}
435
+
436
+ /**
437
+ * @param callable $callable
438
+ * @param string|null $target
439
+ *
440
+ * @return $this
441
+ */
442
+ public function linkTo (callable $ callable , string $ target = null ): self
443
+ {
444
+ $ this ->linkCallback = $ callable ;
445
+ $ this ->linkTarget = $ target ;
446
+
447
+ return $ this ;
448
+ }
415
449
}
You can’t perform that action at this time.
0 commit comments