update datatable

This commit is contained in:
pbao9
2026-01-30 13:56:32 +07:00
parent 9802839056
commit cfe38232c3
10 changed files with 292 additions and 215 deletions
@@ -1,76 +1,24 @@
@php use App\Http\Helpers\Helper; @endphp
@extends('admin.main')
@extends('administrator.layout.master')
@push('plugin-styles')
<link href="{{ asset('build/plugins/select2/select2.min.css') }}" rel="stylesheet" />
@endpush
@section('content')
@if(auth()->guard('admins')->user()->can("manager package module"))
<div class="card card-primary card-outline">
<div class="card-header">
@include("admin.block.Sync.Datacenter")
</div>
<div class="card-body">
<table class="table table-invoice table-bordered">
<thead>
<tr>
<th class="text-center">
<label>
<input type="checkbox" name="check" class="check-all">
</label>
</th>
<th class="text-center">Datacenter Name</th>
<th class="text-center">vCenter Host</th>
<th class="text-center">Last Updated</th>
<th style="width:40px"></th>
<th style="width: 40px"></th>
</tr>
</thead>
<tbody>
@if($datacenter->count())
@foreach($datacenter->all() as $item)
<tr>
<td class="text-center">
<label for=""></label><input type="checkbox" name="id[]" value="{{ $item->id }}"
id="">
</td>
<td class="text-center">
{{ $item->name }}
</td>
<td class="text-center">
@isset($item->vCenter->host)
{{ $item->vCenter->host }}
@endisset
</td>
<td class="text-center">
@time($item->created_at)
</td>
<td>
<a class="btn btn-warning btn-sm"
href="{{ route('package.datacenter.edit', ['id' => $item->id]) }}">
<i class="fas fa-user-edit"></i>
</a>
</td>
<td>
@if(auth()->guard('admins')->user()->can("delete module vcenter"))
<form method="post" class="d-inline"
action="{{ route('package.datacenter.destroy', ['id' => $item->id]) }}">
@method('delete')
@csrf
<button type="submit" data-toggle="tooltip" data-placement="top" title=""
class="btn btn-sm btn-danger" data-original-title="Xoá">
<i class="fas fa-trash"></i>
</button>
</form>
@endif
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
<div class="card-body p-5">
<x-datatable id="datacenterTable" ajax="{{ route('package.datacenter.datatable') }}" :columns="[
['key' => 'id', 'label' => 'ID'],
['key' => 'name', 'label' => 'Name'],
['key' => 'v_center.host', 'label' => 'vCenter Host'],
['key' => 'action', 'label' => 'Action']
]" />
</div>
<div class="card-footer">
{{-- {{ $datacenter->withQueryString()->links() }}--}}
</div>
</div>
@else
<div class="alert alert-danger alert-dismissible">
<h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Module Package
@@ -78,3 +26,13 @@
</div>
@endif
@endsection
@push('plugin-scripts')
<script src="{{ asset('build/plugins/jquery/jquery.min.js') }}"></script>
<script src="{{ asset('build/plugins/select2/select2.min.js') }}"></script>
<script src="{{ asset('build/plugins/datatables.net/dataTables.min.js') }}"></script>
<script src="{{ asset('build/plugins/datatables.net-bs5/dataTables.bootstrap5.min.js') }}"></script>
@endpush
@push('custom-scripts')
@endpush
@@ -55,7 +55,7 @@
@include('administrator.layout.partials.sidebar')
<div class="page-wrapper">
@include('administrator.layout.partials.header')
<div class="page-content container-xxl">
<div class="page-content">
@yield('content')
<div id="fui-toast"></div>
</div>
@@ -6,53 +6,55 @@
<div class="sidebar-toggler not-active">
<span></span><span></span><span></span>
</div>
</div>
<div class="sidebar-body">
<ul class="nav" id="sidebarNav">
@foreach(config('admin-sidebar', []) as $menu)
</div>
<div class="sidebar-body">
<ul class="nav" id="sidebarNav">
@foreach(config('admin-sidebar', []) as $menu)
{{-- CATEGORY --}}
@if(($menu['type'] ?? null) === 'category')
<li class="nav-item nav-category">
{{ $menu['title'] }}
</li>
@endif
{{-- SINGLE ITEM --}}
@if(($menu['type'] ?? null) === 'item')
<li class="nav-item {{ active_class($menu['active'] ?? []) }}">
<a href="{{ url($menu['url']) }}" class="nav-link">
@isset($menu['icon'])
<i class="link-icon" data-lucide="{{ $menu['icon'] }}"></i>
@endisset
<span class="link-title">{{ $menu['title'] }}</span>
</a>
</li>
@endif
{{-- GROUP (COLLAPSE) --}}
@if(($menu['type'] ?? null) === 'group')
@php
$id = \Illuminate\Support\Str::slug($menu['title']);
@endphp
<li class="nav-item {{ active_class($menu['active'] ?? []) }}">
<a class="nav-link" data-bs-toggle="collapse" href="#{{ $id }}" role="button"
aria-expanded="{{ is_active_route($menu['active'] ?? []) }}" aria-controls="{{ $id }}">
{{-- CATEGORY --}}
@if(($menu['type'] ?? null) === 'category')
<li class="nav-item nav-category">
{{ $menu['title'] }}
</li>
@endif
{{-- SINGLE ITEM --}}
@if(($menu['type'] ?? null) === 'item')
<li class="nav-item {{ request()->routeIs(...($menu['active'] ?? [])) ? 'active' : '' }}">
<a href="{{ route($menu['route'], $menu['params'] ?? []) }}" class="nav-link">
@isset($menu['icon'])
<i class="link-icon" data-lucide="{{ $menu['icon'] }}"></i>
<span class="link-title">{{ $menu['title'] }}</span>
<i class="link-arrow" data-lucide="chevron-down"></i>
</a>
@endisset
<span class="link-title">{{ $menu['title'] }}</span>
</a>
</li>
@endif
<div class="collapse {{ show_class($menu['active'] ?? []) }}" id="{{ $id }}" data-bs-parent="#sidebarNav">
{{-- GROUP (COLLAPSE) --}}
@if(($menu['type'] ?? null) === 'group')
@php
$id = \Illuminate\Support\Str::slug($menu['title']);
$isActive = request()->routeIs(...($menu['active'] ?? []));
@endphp
<li class="nav-item {{ $isActive ? 'active' : '' }}">
<a class="nav-link" data-bs-toggle="collapse" href="#{{ $id }}" role="button"
aria-expanded="{{ $isActive ? 'true' : 'false' }}" aria-controls="{{ $id }}">
<i class="link-icon" data-lucide="{{ $menu['icon'] }}"></i>
<span class="link-title">{{ $menu['title'] }}</span>
<i class="link-arrow" data-lucide="chevron-down"></i>
</a>
<div class="collapse {{ $isActive ? 'show' : '' }}" id="{{ $id }}" data-bs-parent="#sidebarNav">
<ul class="nav sub-menu">
@foreach($menu['children'] ?? [] as $child)
<li class="nav-item">
<a href="{{ url($child['url']) }}" class="nav-link {{ active_class($child['active'] ?? []) }}">
<a href="{{ route($child['route'], $child['params'] ?? []) }}"
class="nav-link {{ request()->routeIs(...($child['active'] ?? [])) ? 'active' : '' }}">
{{ $child['title'] }}
</a>
</li>
@@ -61,10 +63,10 @@
</div>
</li>
@endif
@endif
@endforeach
</ul>
</div>
</nav>
@endforeach
</ul>
</div>
</nav>
+86 -29
View File
@@ -1,35 +1,92 @@
@php
$dtColumns = collect($columns)->map(function ($c) {
return [
'data' => $c['key'],
'name' => $c['key'],
'orderable' => $c['orderable'] ?? true,
'searchable' => $c['searchable'] ?? true,
];
return [
'data' => $c['key'],
'name' => $c['key'],
'orderable' => $c['orderable'] ?? true,
'searchable' => $c['searchable'] ?? true,
];
})->values();
@endphp
<div class="table-responsive">
<table id="{{ $id }}" class="table table-striped w-100">
<thead>
<tr>
@foreach($columns as $col)
<th>{{ $col['label'] }}</th>
@endforeach
</tr>
<table id="{{ $id }}" class="table table-hover table-bordered w-100 align-middle my-3">
<thead>
<tr>
@foreach($columns as $col)
<th>{{ $col['label'] }}</th>
@endforeach
</tr>
<tr>
@foreach($columns as $col)
<th>
@if(($col['searchable'] ?? true))
<input type="text" class="form-control form-control-sm column-search" placeholder="Search {{ $col['label'] }}"
data-column="{{ $loop->index }}">
@endif
</th>
@endforeach
</tr>
</thead>
</table>
</div>
</table>
@push('custom-scripts')
<script>
document.addEventListener('DOMContentLoaded', function () {
$.fn.DataTable.ext.pager.numbers_length = 7;
@push('custom-scripts')
<script>
document.addEventListener('DOMContentLoaded', function () {
$('#{{ $id }}').DataTable({
processing: true,
serverSide: true,
ajax: '{{ $ajax }}',
columns: @json($dtColumns),
});
});
</script>
@endpush
var table = $('#{{ $id }}').DataTable({
processing: true,
serverSide: true,
ajax: '{{ $ajax }}',
columns: @json($dtColumns),
orderCellsTop: true, // Important for the second header row
fixedHeader: true,
pagingType: 'full_numbers',
language: {
searchPlaceholder: "Search records",
search: "",
lengthMenu: "_MENU_",
},
dom: "<'row'<'col-sm-12'<'table-responsive'tr>>>" +
"<'row mt-3 align-items-center'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 d-flex align-items-center justify-content-end gap-2'lp>>",
initComplete: function () {
// Initialize select2 for length menu
$('.dataTables_length select').select2({
minimumResultsForSearch: Infinity,
width: '60px'
});
// Apply the search
this.api().columns().every(function () {
var that = this;
$('input', this.header()).on('keyup change clear', function () {
if (that.search() !== this.value) {
that
.search(this.value)
.draw();
}
});
});
},
drawCallback: function() {
if ($('.dataTables_length select').data('select2')) {
$('.dataTables_length select').select2('destroy');
}
$('.dataTables_length select').select2({
minimumResultsForSearch: Infinity,
width: '60px'
});
}
});
// Prevent sorting when clicking on the input
$('#{{ $id }} thead tr:eq(1) th').on('click', function (e) {
e.stopPropagation();
});
// Custom search logic for the individual inputs
$('#{{ $id }} .column-search').on('keyup change', function () {
var columnIndex = $(this).data('column');
table.column(columnIndex).search(this.value).draw();
});
});
</script>
@endpush