Skip to content

Commit b8e4c37

Browse files
committed
Initial Commit
1 parent b026e05 commit b8e4c37

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

src/Traits/Configuration/ColumnConfiguration.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ trait ColumnConfiguration
88
{
99
public function setPrependedColumns(array $prependedColumns): void
1010
{
11-
$this->prependedColumns = collect($prependedColumns)
11+
$this->prependedColumns = collect($prependedColumns);
12+
$this->hasRunColumnSetup = false;
13+
/*
14+
1215
->filter(fn ($column) => $column instanceof Column)
1316
->map(function (Column $column) {
1417
$column->setTheme($this->getTheme());
@@ -24,12 +27,15 @@ public function setPrependedColumns(array $prependedColumns): void
2427
}
2528
2629
return $column;
27-
});
30+
});*/
2831
}
2932

3033
public function setAppendedColumns(array $appendedColumns): void
3134
{
32-
$this->appendedColumns = collect($appendedColumns)
35+
$this->appendedColumns = collect($appendedColumns);
36+
$this->hasRunColumnSetup = false;
37+
/*
38+
3339
->filter(fn ($column) => $column instanceof Column)
3440
->map(function (Column $column) {
3541
$column->setTheme($this->getTheme());
@@ -45,7 +51,7 @@ public function setAppendedColumns(array $appendedColumns): void
4551
}
4652
4753
return $column;
48-
});
54+
});*/
4955
}
5056

5157
public function unsetCollapsedStatuses(): void

src/Traits/Helpers/ColumnHelpers.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ trait ColumnHelpers
1313
*/
1414
public function setColumns(): void
1515
{
16-
$this->prependedColumns = $this->getPrependedColumns();
16+
$this->columns = collect($this->getPrependedColumns())->concat($this->columns())->concat(collect($this->getAppendedColumns()));
1717

18-
$columns = collect($this->columns())
18+
}
19+
20+
protected function setupColumns(): void
21+
{
22+
if(!$this->hasRunColumnSetup)
23+
{
24+
$this->columns = $this->columns
1925
->filter(fn ($column) => $column instanceof Column)
2026
->map(function (Column $column) {
21-
$column->setTheme($this->getTheme());
22-
$column->setHasTableRowUrl($this->hasTableRowUrl());
23-
$column->setIsReorderColumn($this->getDefaultReorderColumn() == $column->getField());
27+
$column->setTheme($this->getTheme())
28+
->setHasTableRowUrl($this->hasTableRowUrl())
29+
->setIsReorderColumn($this->getDefaultReorderColumn() == $column->getField());
30+
2431
if ($column instanceof AggregateColumn) {
2532
if ($column->getAggregateMethod() == 'count' && $column->hasDataSource()) {
2633
$this->addExtraWithCount($column->getDataSource());
@@ -42,13 +49,16 @@ public function setColumns(): void
4249
return $column;
4350
});
4451

45-
$this->appendedColumns = $this->getAppendedColumns();
46-
47-
$this->columns = collect([...$this->prependedColumns, ...$columns, ...$this->appendedColumns]);
52+
$this->hasRunColumnSetup = true;
53+
}
4854
}
4955

5056
public function getColumns(): Collection
5157
{
58+
if(!$this->hasRunColumnSetup)
59+
{
60+
$this->setupColumns();
61+
}
5262
return $this->columns;
5363
}
5464

@@ -206,7 +216,8 @@ public function getColspanCount(): int
206216

207217
public function getPrependedColumns(): Collection
208218
{
209-
return collect($this->prependedColumns ?? $this->prependColumns())
219+
return collect($this->prependedColumns ?? $this->prependColumns());
220+
/*return collect($this->prependedColumns ?? $this->prependColumns())
210221
->filter(fn ($column) => $column instanceof Column)
211222
->map(function (Column $column) {
212223
$column->setTheme($this->getTheme());
@@ -231,13 +242,13 @@ public function getPrependedColumns(): Collection
231242
}
232243
233244
return $column;
234-
});
245+
});*/
235246
}
236247

237248
public function getAppendedColumns(): Collection
238249
{
239-
return collect($this->appendedColumns ?? $this->appendColumns())
240-
->filter(fn ($column) => $column instanceof Column)
250+
return collect($this->appendedColumns ?? $this->appendColumns());
251+
/*->filter(fn ($column) => $column instanceof Column)
241252
->map(function (Column $column) {
242253
$column->setTheme($this->getTheme());
243254
$column->setHasTableRowUrl($this->hasTableRowUrl());
@@ -261,7 +272,7 @@ public function getAppendedColumns(): Collection
261272
}
262273
263274
return $column;
264-
});
275+
});*/
265276

266277
}
267278

src/Traits/WithColumns.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ trait WithColumns
2525

2626
protected ?bool $shouldTabletCollapse;
2727

28+
protected bool $hasRunColumnSetup = false;
29+
2830
/**
2931
* Sets up Columns
3032
*/
@@ -39,7 +41,7 @@ public function bootedWithColumns(): void
3941

4042
// Set Columns
4143
$this->setColumns();
42-
44+
4345
// Fire Lifecycle Hooks for columnsSet
4446
$this->callHook('columnsSet');
4547
$this->callTraitHook('columnsSet');

0 commit comments

Comments
 (0)