{{-- ==================================================================== 📊 REUSABLE AJAX DATATABLE COMPONENT ==================================================================== USAGE EXAMPLE: @include('admin.partial.datatable', [ 'title' => 'Category Management', 'subtitle' => 'Manage all categories', // optional 'columns' => [ ['label' => 'SL', 'field' => 'id', 'sortable' => true], ['label' => 'Name', 'field' => 'name', 'sortable' => true], ['label' => 'Status', 'field' => 'status'], ['label' => 'Action', 'field' => 'action'], ], 'ajax_route' => route('category.index'), 'store_route' => route('category.store'), // optional, defaults to ajax_route 'update_route' => route('category.update', ':id'), // optional, defaults to ajax_route/:id 'delete_route' => route('category.destroy', ':id'), // optional 'filters' => [ 'search' => true, 'status' => true, 'parent_category' => $pluck_categories ?? null, // pass dropdown data 'date_range' => true, 'custom' => [ // optional custom filters ['name' => 'division', 'label' => 'Division', 'options' => $divisions], ] ], 'modal_fields' => [ // Form fields for Add/Edit modal ['name' => 'name', 'label' => 'Name', 'type' => 'text', 'required' => true], ['name' => 'bn_name', 'label' => 'Bangla Name', 'type' => 'text', 'required' => true], ['name' => 'parent_id', 'label' => 'Parent Category', 'type' => 'select', 'options' => $pluck_categories], ['name' => 'status', 'label' => 'Status', 'type' => 'select', 'options' => [1 => 'Active', 0 => 'Inactive']], ['name' => 'image', 'label' => 'Image', 'type' => 'file', 'accept' => 'image/*'], ], 'show_add_button' => true, // optional, default true 'show_filters' => true, // optional, default true 'per_page_options' => [10, 20, 50, 100], // optional ]) --}} @php $title = $title ?? 'Data Management'; $subtitle = $subtitle ?? ''; $columns = $columns ?? []; $ajax_route = $ajax_route ?? '#'; $store_route = $store_route ?? $ajax_route; $update_route = $update_route ?? $ajax_route . '/:id'; $delete_route = $delete_route ?? $ajax_route . '/:id'; $filters = $filters ?? []; $modal_fields = $modal_fields ?? []; $show_add_button = $show_add_button ?? true; $show_filters = $show_filters ?? true; $per_page_options = $per_page_options ?? [10, 20, 50, 100]; $unique_id = 'dt_' . uniqid(); // Unique ID for multiple tables on same page @endphp
📊 {{ $title }}
@if ($subtitle)
{{ $subtitle }}
@endif
@if ($show_add_button) @endif
Show:
@if (isset($filters['search']) && $filters['search'])
@endif
@if ($show_filters && !empty($filters))
@if (isset($filters['status']) && $filters['status'])
@endif @if (isset($filters['parent_category']))
@endif @if (isset($filters['date_range']) && $filters['date_range'])
@endif @if (isset($filters['custom'])) @foreach ($filters['custom'] as $custom)
@endforeach @endif
@endif
@foreach ($columns as $col) @endforeach
{{ $col['label'] }}
Loading...