@props([ 'id' => 'datatable-' . uniqid(), // ID فريد للجدول 'columns' => [], // أعمدة الجدول (headers) 'fields' => [], // fields البيانات المقابلة 'actions' => [], // روابط الإجراءات: [view, edit, delete] أو custom 'url' => null, // Ajax URL (null = window.location.href) 'serverSide' => true, // Server-side processing 'order' => [[0, 'DESC']], // ترتيب افتراضي 'addNew' => null, // نص زر إضافة جديد 'addNewUrl' => null, // رابط زر إضافة جديد 'exportable' => true, // إظهار أزرار التصدير 'searchable' => true, // إظهار بحث في footer 'exportCols' => null, // عمود export (null = كل الأعمدة) 'extra' => [], // columnDefs إضافية 'class' => '', // class إضافية للجدول ]) @php $tableId = $id; $ajaxUrl = $url ?? 'window.location.href'; $ajaxUrlJs = $url ? "'{$url}'" : 'window.location.href'; // بناء columns JS $jsColumns = []; foreach ($fields as $field) { if (is_array($field)) { $jsColumns[] = $field; // مرّر كـ-is } else { $jsColumns[] = ['data' => $field]; } } // هل في عمود action؟ $hasActions = !empty($actions); if ($hasActions) { $jsColumns[] = ['data' => 'action', 'orderable' => false, 'searchable' => false]; } // بناء action HTML $actionItems = ''; foreach ($actions as $action) { $type = $action['type'] ?? 'custom'; if ($type === 'view') { $href = $action['url'] ?? '#'; $label = $action['label'] ?? __('trans.view'); $icon = $action['icon'] ?? 'fa-regular fa-eye'; $dataAttrs = ''; foreach ($action['data'] ?? [] as $attr => $field) { $dataAttrs .= " data-{$attr}=\"\${row.{$field}}\""; } $actionItems .= "
| {{ $col['label'] }} | @else{{ $col }} | @endif @endforeach @if($hasActions){{ __('trans.actions') }} | @endif
|---|---|---|