bd 3.0
This commit is contained in:
@ -12,10 +12,14 @@ class TableJsonWidget extends BaseWidget
|
||||
private string $html = '';
|
||||
private string $json;
|
||||
|
||||
private int $count = 0;
|
||||
private \Closure|false $beforePrintCell;
|
||||
|
||||
private array $data;
|
||||
|
||||
public function __construct(string $json)
|
||||
{
|
||||
$this->beforePrintCell = false;
|
||||
$this->json = $json;
|
||||
$this->data = json_decode($this->json, true);
|
||||
}
|
||||
@ -33,6 +37,7 @@ class TableJsonWidget extends BaseWidget
|
||||
}
|
||||
|
||||
$this->html .= "<thead><tr>";
|
||||
$this->html .= "<th>" . "ID" . "</th>";
|
||||
foreach ($this->data['meta']['columns'] as $key => $column){
|
||||
$this->html .= "<th>" . $column . "</th>";
|
||||
}
|
||||
@ -44,8 +49,15 @@ class TableJsonWidget extends BaseWidget
|
||||
if ($this->data['data']){
|
||||
foreach ($this->data['data'] as $col){
|
||||
$this->html .= "<tr>";
|
||||
$this->count += 1;
|
||||
$this->html .= "<td>" . $this->count . "</td>";
|
||||
foreach ($col as $key => $row){
|
||||
if ($this->issetColumn($key)){
|
||||
if ($this->beforePrintCell){
|
||||
$hook = $this->beforePrintCell;
|
||||
$row = $hook($key, $row);
|
||||
}
|
||||
|
||||
$this->html .= "<td>" . $row . "</td>";
|
||||
}
|
||||
}
|
||||
@ -97,4 +109,9 @@ class TableJsonWidget extends BaseWidget
|
||||
{
|
||||
echo $this->html;
|
||||
}
|
||||
|
||||
public function setBeforePrintCell(\Closure $closure): void
|
||||
{
|
||||
$this->beforePrintCell = $closure;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user