Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit c4ee5e8

Browse files
authored
Table alignment (#379)
1 parent e49f9be commit c4ee5e8

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

app/app/Tables/Projects.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public function configure(SpladeTable $table)
5959
->column('updated_at', 'Project Updated', exportFormat: function () {
6060
return NumberFormat::FORMAT_DATE_TIME2;
6161
})
62-
->column('organization.name', searchable: true, sortable: true, exportAs: false)
62+
->column('organization.name', searchable: true, sortable: true, exportAs: false, alignment: 'center')
6363
->column('organization.address.city', 'Organization City', sortable: true, exportStyling: function (Style $style) {
6464
$style->getFont()->setBold(true);
65-
})
65+
}, alignment: 'right')
6666
->paginate(15);
6767
}
6868
}

resources/views/table/body.blade.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ class="rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300
3131
v-show="table.columnIsVisible(@js($column->key))"
3232
class="whitespace-nowrap text-sm @if($loop->first && $hasBulkActions) pr-6 @else px-6 @endif py-4 @if($column->highlight) text-gray-900 font-medium @else text-gray-500 @endif @if($table->rowLinks->has($itemKey)) cursor-pointer @endif {{ $column->classes }}"
3333
>
34-
@isset(${'spladeTableCell' . $column->keyHash()})
35-
{{ ${'spladeTableCell' . $column->keyHash()}($item, $itemKey) }}
36-
@else
37-
{!! nl2br(e($getColumnDataFromItem($item, $column))) !!}
38-
@endisset
34+
<div class="flex flex-row items-center @if($column->alignment == 'right') justify-end @elseif($column->alignment == 'center') justify-center @else justify-start @endif">
35+
@isset(${'spladeTableCell' . $column->keyHash()})
36+
{{ ${'spladeTableCell' . $column->keyHash()}($item, $itemKey) }}
37+
@else
38+
{!! nl2br(e($getColumnDataFromItem($item, $column))) !!}
39+
@endisset
40+
</div>
3941
</td>
4042
@endforeach
4143
</tr>

resources/views/table/head.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class="@if($loop->first && $hasBulkActions) pr-6 @else px-6 @endif py-3 text-lef
1515
<Link keep-modal dusk="sort-{{ $column->key }}" href="{{ $sortBy($column) }}">
1616
@endif
1717

18-
<span class="flex flex-row items-center">
19-
<span class="uppercase w-full">{{ $column->label }}</span>
18+
<span class="flex flex-row items-center @if($column->alignment == 'right') justify-end @elseif($column->alignment == 'center') justify-center @else justify-start @endif">
19+
<span class="uppercase">{{ $column->label }}</span>
2020

2121
@if($column->sortable)
2222
<svg aria-hidden="true" class="w-3 h-3 ml-2 @if($column->sorted) text-green-500 @else text-gray-400 @endif" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">

src/Table/Column.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct(
2929
public Closure|array|null $exportStyling = null,
3030
public array|string|null $classes = null,
3131
public Closure|null $as = null,
32+
public string $alignment = 'left',
3233
) {
3334
if (is_array($classes)) {
3435
$classes = Arr::flatten($classes);
@@ -55,6 +56,7 @@ public function clone(): static
5556
$this->exportStyling,
5657
$this->classes,
5758
$this->as,
59+
$this->alignment,
5860
);
5961
}
6062

@@ -73,6 +75,7 @@ public function toArray()
7375
'sortable' => $this->sortable !== false,
7476
'sorted' => $this->sorted,
7577
'highlight' => $this->highlight,
78+
'alignment' => $this->alignment,
7679
];
7780
}
7881

src/Table/HasColumns.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function column(
5757
callable|array|null $exportStyling = null,
5858
array|string|null $classes = null,
5959
callable|null $as = null,
60+
string $alignment = 'left',
6061
): self {
6162
$key = $key !== null ? $key : Str::kebab($label);
6263
$label = $label !== null ? $label : Str::headline(str_replace('.', ' ', $key));
@@ -84,6 +85,7 @@ public function column(
8485
exportStyling: $exportStyling,
8586
classes: $classes,
8687
as: $as,
88+
alignment: $alignment,
8789
))->values();
8890

8991
if (!$searchable) {

0 commit comments

Comments
 (0)