@props([ 'id' => null, 'title' => null, 'description' => null, 'columns' => [], 'rows' => [], 'addUrl' => null, 'addLabel' => null, 'emptyText' => null, 'minWidth' => '760px', ]) @php $addLabel = $addLabel ?: __('kview-ui-data::table.add_record'); $emptyText = $emptyText ?: __('kview-ui-data::table.no_records_yet'); $columns = app(\Kview\UiData\TableColumnRegistry::class)->normalizeMany($columns); $types = app(\Kview\UiData\TableCellTypeRegistry::class); $tableId = $id ?: 'erp-detail-table-'.str()->random(8); $previewDrawerId = $tableId.'_preview_drawer'; $hasActions = collect($rows)->contains(fn ($row) => ! empty($row['actions'])); $hasPreviewActions = collect($rows)->contains(function ($row) { return collect($row['actions'] ?? [])->contains(fn ($action) => ! empty($action['preview'])); }); $columnCount = count($columns) + ($hasActions ? 1 : 0); @endphp
class('erp-detail-table') }} data-erp-detail-table style="--erp-detail-table-min-width: {{ $minWidth }};" > @if ($title || $description || $addUrl) @if ($addUrl) @endif @endif
@foreach ($columns as $column) @php $columnStyle = collect([ ! empty($column['width']) ? 'width: '.$column['width'] : null, ! empty($column['minWidth']) ? 'min-width: '.$column['minWidth'] : null, ])->filter()->implode('; '); @endphp @endforeach @if ($hasActions) @endif @forelse ($rows as $row) @foreach ($columns as $column) @php $key = $column['key']; $cell = $row['cells'][$key] ?? null; $cellArray = is_array($cell) ? $cell : ['value' => $cell]; $cellType = $types->normalize($cellArray['type'] ?? $column['type']); $cellTypeDefinition = $types->definition($cellType); $cellAlignment = $cellArray['alignment'] ?? $cellArray['align'] ?? $column['alignment'] ?? $cellTypeDefinition['alignment']; $cellStyle = collect([ ! empty($column['width']) ? 'width: '.$column['width'] : null, ! empty($column['minWidth']) ? 'min-width: '.$column['minWidth'] : null, ])->filter()->implode('; '); @endphp @endforeach @if ($hasActions) @endif @empty @endforelse
$column['numeric'], 'is-nowrap' => $column['nowrap'], 'is-align-'.$column['alignment'], ]) data-erp-column-type="{{ $column['type'] }}" data-erp-column-alignment="{{ $column['alignment'] }}" @if ($columnStyle) style="{{ $columnStyle }}" @endif > {{ $column['label'] ?? $column['key'] ?? '' }} {{ __('kview-ui-data::table.actions') }}
$cellTypeDefinition['numeric'], 'is-nowrap' => $column['nowrap'] || $cellTypeDefinition['nowrap'], 'is-align-'.$cellAlignment, ]) data-erp-column-type="{{ $cellType }}" data-erp-column-alignment="{{ $cellAlignment }}" @if ($cellStyle) style="{{ $cellStyle }}" @endif >
{{ $emptyText }}
@if ($hasPreviewActions) @endif