File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-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
/**
@@ -79,6 +80,16 @@ class Column
79
80
*/
80
81
public bool $ selected = false ;
81
82
83
+ /**
84
+ * @var
85
+ */
86
+ public $ linkCallback ;
87
+
88
+ /**
89
+ * @var string
90
+ */
91
+ public string $ linkTarget ;
92
+
82
93
/**
83
94
* Column constructor.
84
95
*
@@ -268,6 +279,14 @@ public function formatted($row, $column = null)
268
279
$ value = call_user_func ($ this ->formatCallback , $ value , $ column , $ row );
269
280
}
270
281
282
+ if ($ this ->linkCallback ) {
283
+ $ url = call_user_func ($ this ->linkCallback , $ value , $ column , $ row );
284
+ if ($ url ) {
285
+ $ linkTarget = $ this ->linkTarget ? "target=' $ this ->linkTarget ' " : '' ;
286
+ $ value = new HtmlString ("<a href=' $ url' $ linkTarget> $ value</a> " );
287
+ }
288
+ }
289
+
271
290
return $ value ;
272
291
}
273
292
@@ -358,4 +377,17 @@ public function isSelected(): bool
358
377
{
359
378
return $ this ->selected ;
360
379
}
380
+
381
+ /**
382
+ * @param callable $callable
383
+ * @param ?string $target
384
+ *
385
+ * @return $this
386
+ */
387
+ public function linkTo (callable $ callable , string $ target = null ): self
388
+ {
389
+ $ this ->linkCallback = $ callable ;
390
+ $ this ->linkTarget = $ target ;
391
+ return $ this ;
392
+ }
361
393
}
You can’t perform that action at this time.
0 commit comments