@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 .= "
  • {$label}
  • "; } elseif ($type === 'edit') { $baseUrl = $action['url'] ?? ''; $label = $action['label'] ?? __('trans.edit'); $icon = $action['icon'] ?? 'fa-regular fa-edit'; $dataAttrs = ''; foreach ($action['data'] ?? [] as $attr => $field) { $dataAttrs .= " data-{$attr}=\"\${row.{$field}}\""; } $actionItems .= "
  • {$label}
  • "; } elseif ($type === 'delete') { $baseUrl = $action['url'] ?? ''; $label = $action['label'] ?? __('trans.delete'); $icon = $action['icon'] ?? 'fa-solid fa-trash'; $csrf = csrf_field(); $method = method_field('DELETE'); $dataAttrs = ''; foreach ($action['data'] ?? [] as $attr => $field) { $dataAttrs .= " data-{$attr}=\"\${row.{$field}}\""; } $actionItems .= "
  • {$csrf}{$method}
  • "; } elseif ($type === 'custom') { // custom: يتوقع 'render' => JS string تحتوي على ${row.id} $actionItems .= $action['html'] ?? ''; } } @endphp {{-- ================== HTML ================== --}} @foreach ($columns as $col) @if(is_array($col)) @else @endif @endforeach @if($hasActions) @endif
    {{ $col['label'] }}{{ $col }}{{ __('trans.actions') }}
    @once @push('css') {{-- CSS --}} @endpush {{-- js --}} @push('js') @endpush @endonce @push('js') {{-- ================== JS ================== --}} @endpush