update datatable

This commit is contained in:
pbao9
2026-02-03 10:04:55 +07:00
parent 214fca9ef6
commit b6e4915841
5 changed files with 352 additions and 190 deletions
@@ -4,55 +4,55 @@
<link href="{{ asset($css) }}" rel="stylesheet" /> <link href="{{ asset($css) }}" rel="stylesheet" />
@endforeach @endforeach
@endpush @endpush
@section('breadcrumb') @section('breadcrumb')
@php @php
$breadcrumbItems = [ $breadcrumbItems = [
['label' => 'Modules',], ['label' => 'Modules',],
['label' => 'Package vCenter', 'url' => route('package.datacenter.index')], ['label' => 'Package vCenter', 'url' => route('package.datacenter.index')],
['label' => 'Datacenter', 'active' => true], ['label' => 'Datacenter', 'active' => true],
]; ];
@endphp @endphp
<x-admin-breadcrumb :items="$breadcrumbItems" /> <x-admin-breadcrumb :items="$breadcrumbItems" />
@endsection @endsection
@section("content") @section("content")
@if(auth()->guard('admins')->user()->can("add module vcenter")) @if(auth()->guard('admins')->user()->can("add module vcenter"))
<div class="card card-outline card-primary"> <div class="card card-outline card-primary">
<form action="{{ route('package.datacenter.store') }}" method="post"> <form action="{{ route('package.datacenter.store') }}" method="post">
@csrf @csrf
<div class="card-body"> <div class="card-body">
<x-module.v-center :model="null" /> <x-module.v-center :model="null" />
{{--Name--}} {{--Name--}}
<div class="row form-group align-items-center mb-0"> <div class="row form-group align-items-center mb-0">
<label for="name" class="col-md-3 text-right">Name</label> <label for="name" class="col-md-3 text-right">Name</label>
<div class="col-md-9 p-1 bg-customer"> <div class="col-md-9 p-1 bg-customer">
<input type="text" id="name" name="name" placeholder="" value="" class="form-control"> <input type="text" id="name" name="name" placeholder="" value="" class="form-control">
</div>
</div>
{{--Datacenter ID--}}
<div class="row form-group align-items-center mb-0">
<label for="datacenter_id" class="col-md-3 text-right">Datacenter ID</label>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="datacenter_id" name="datacenter_id" placeholder="" value=""
class="form-control">
</div>
</div> </div>
</div> </div>
<div class="card-footer"> {{--Datacenter ID--}}
<a href="{{ route('package.datacenter.index') }}" class="btn btn-outline-secondary">Trở về</a> <div class="row form-group align-items-center mb-0">
<button type="submit" class="btn btn-outline-primary">Lưu dữ liệu</button> <label for="datacenter_id" class="col-md-3 text-right">Datacenter ID</label>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="datacenter_id" name="datacenter_id" placeholder="" value=""
class="form-control">
</div>
</div> </div>
</form> </div>
</div> <div class="card-footer">
@else <a href="{{ route('package.datacenter.index') }}" class="btn btn-outline-secondary">Trở về</a>
<div class="alert alert-danger alert-dismissible"> <button type="submit" class="btn btn-outline-primary">Lưu dữ liệu</button>
<h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Module vCenter </div>
management department</h5> </form>
</div> </div>
@endif @else
@endsection <div class="alert alert-danger alert-dismissible">
@push('plugin-scripts') <h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Module vCenter
@foreach (config('assets.datatable.js') as $js) management department</h5>
<script src="{{ asset($js) }}"></script> </div>
@endforeach @endif
@endpush @endsection
@push('plugin-scripts')
@foreach (config('assets.datatable.js') as $js)
<script src="{{ asset($js) }}"></script>
@endforeach
@endpush
@@ -1,60 +1,61 @@
@extends("administrator.layout.master") @extends("administrator.layout.master")
@push('plugin-styles') @push('plugin-styles')
<link href="{{ asset('build/plugins/select2/select2.min.css') }}" rel="stylesheet" /> @foreach (config('assets.datatable.css') as $css)
<link href="{{ asset($css) }}" rel="stylesheet" />
@endforeach
@endpush @endpush
@section('breadcrumb') @section('breadcrumb')
@php @php
$breadcrumbItems = [ $breadcrumbItems = [
['label' => 'Modules'], ['label' => 'Modules',],
['label' => 'Package vCenter'], ['label' => 'Package vCenter', 'url' => route('package.datacenter.index')],
['label' => 'Datacenter', 'active' => true], ['label' => 'Datacenter'],
]; ['label' => 'Edit', 'active' => true],
@endphp ];
<x-admin-breadcrumb :items="$breadcrumbItems" /> @endphp
@endsection <x-admin-breadcrumb :items="$breadcrumbItems" />
@section("content") @endsection
@if(auth()->guard('admins')->user()->can("add module vcenter")) @section("content")
<div class="card card-outline card-primary"> @if(auth()->guard('admins')->user()->can("add module vcenter"))
<form action="{{ route('package.datacenter.update', ['id' => $datacenter->id]) }}" method="post"> <div class="card card-outline card-primary">
@csrf <form action="{{ route('package.datacenter.update', ['id' => $datacenter->id]) }}" method="post">
@method('put') @csrf
<div class="card-body"> @method('put')
<x-module.v-center :model="$datacenter" /> <div class="card-body">
{{--Name--}} <x-module.v-center :model="$datacenter" />
<div class="row form-group align-items-center mb-0"> {{--Name--}}
<label for="name" class="col-md-3 text-right">Name</label> <div class="row form-group align-items-center mb-0">
<div class="col-md-9 p-1 bg-customer"> <label for="name" class="col-md-3 text-right">Name</label>
<input type="text" id="name" name="name" placeholder="" value="{{$datacenter->name}}" <div class="col-md-9 p-1 bg-customer">
class="form-control"> <input type="text" id="name" name="name" placeholder="" value="{{$datacenter->name}}"
class="form-control">
</div>
</div>
{{--Datacenter ID--}}
<div class="row form-group align-items-center mb-0">
<label for="datacenter_id" class="col-md-3 text-right">Datacenter ID</label>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="datacenter_id" name="datacenter_id" placeholder=""
value="{{$datacenter->datacenter_id}}" class="form-control">
</div>
</div> </div>
</div> </div>
{{--Datacenter ID--}} <div class="card-footer">
<div class="row form-group align-items-center mb-0"> <a href="{{ route('package.datacenter.index') }}" class="btn btn-outline-secondary">Trở về</a>
<label for="datacenter_id" class="col-md-3 text-right">Datacenter ID</label> <button type="submit" class="btn btn-outline-primary">Lưu dữ liệu</button>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="datacenter_id" name="datacenter_id" placeholder=""
value="{{$datacenter->datacenter_id}}" class="form-control">
</div>
</div> </div>
</div> </form>
<div class="card-footer"> </div>
<a href="{{ route('package.datacenter.index') }}" class="btn btn-outline-secondary">Trở về</a> @else
<button type="submit" class="btn btn-outline-primary">Lưu dữ liệu</button> <div class="alert alert-danger alert-dismissible">
</div> <h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Module vCenter
</form> management department</h5>
</div> </div>
@else @endif
<div class="alert alert-danger alert-dismissible"> @endsection
<h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Module vCenter
management department</h5> @push('plugin-scripts')
</div> @foreach (config('assets.datatable.js') as $js)
@endif <script src="{{ asset($js) }}"></script>
@endsection @endforeach
@endpush
@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
@@ -17,7 +17,7 @@ $breadcrumbItems = [
@endsection @endsection
@section('content') @section('content')
@if (auth()->guard('admins')->user()->can('manager package module')) @if (auth()->guard('admins')->user()->can('manager package module'))
<div class="card card-primary card-outline rounded-4"> <div class="card card-primary card-outline rounded-3 border-primary-subtle">
<div class="card-header d-flex justify-content-end gap-2"> <div class="card-header d-flex justify-content-end gap-2">
@include('administrator.pages.block.Sync.Datacenter') @include('administrator.pages.block.Sync.Datacenter')
</div> </div>
@@ -1,7 +1,7 @@
@props(['items' => []]) @props(['items' => []])
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb bg-white shadow-sm p-3 rounded-4 d-flex align-items-center mb-4"> <ol class="breadcrumb bg-white shadow-sm p-3 rounded-3 d-flex align-items-center mb-4">
<li class="breadcrumb-item"> <li class="breadcrumb-item">
<a href="{{ route('dashboard') }}" <a href="{{ route('dashboard') }}"
class="d-flex align-items-center text-muted text-decoration-none transition-colors hover-text-primary"> class="d-flex align-items-center text-muted text-decoration-none transition-colors hover-text-primary">
+247 -86
View File
@@ -1,95 +1,256 @@
@props(['id', 'columns', 'ajax'])
@php @php
$dtColumns = collect($columns)->map(function ($c) { $dtColumns = collect($columns)->map(function ($c) {
return [ return [
'data' => $c['key'], 'data' => $c['key'],
'name' => $c['key'], 'name' => $c['key'],
'orderable' => $c['orderable'] ?? true, 'orderable' => $c['orderable'] ?? true,
'searchable' => $c['searchable'] ?? true, 'searchable' => $c['searchable'] ?? true,
]; 'className' => $c['className'] ?? '',
})->values(); ];
})->values();
@endphp @endphp
<table id="{{ $id }}" class="table table-hover table-bordered w-100 align-middle my-3"> <div class="data-table-wrapper rounded-3 overflow-hidden border border-light">
<thead> <table id="{{ $id }}" class="table table-hover align-middle mb-0 bg-white"
<tr> style="width:100%; border-collapse: separate; border-spacing: 0;">
@foreach($columns as $col) <thead class="bg-light">
<th>{{ $col['label'] }}</th> <tr>
@endforeach @foreach($columns as $col)
</tr> <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-3 py-3 border-bottom"
<tr> style="font-size: 0.75rem; letter-spacing: 0.5px;">
@foreach($columns as $col) {{ $col['label'] }}
<th> </th>
@if(($col['searchable'] ?? true)) @endforeach
<input type="text" class="form-control form-control-sm column-search" placeholder="Search {{ $col['label'] }}" </tr>
data-column="{{ $loop->index }}"> <tr class="filter-row bg-light">
@endif @foreach($columns as $col)
</th> <th class="p-2 border-bottom">
@endforeach @if(($col['searchable'] ?? true))
</tr> <div class="input-group input-group-sm">
</thead> <span class="input-group-text bg-white border-end-0 ps-2 pe-2 text-muted border-light">
</table> <i data-lucide="search" style="font-size: 0.75rem;"></i>
@push('custom-scripts') </span>
<script> <input type="text"
document.addEventListener('DOMContentLoaded', function () { class="form-control form-control-sm border-start-0 ps-0 column-search shadow-none border-light bg-white"
$.fn.DataTable.ext.pager.numbers_length = 7; placeholder="Filter..." data-column="{{ $loop->index }}" style="font-size: 0.8125rem;">
</div>
@endif
</th>
@endforeach
</tr>
</thead>
<tbody>
{{-- DataTables will populate this --}}
</tbody>
</table>
</div>
@push('custom-scripts')
<script>
document.addEventListener('DOMContentLoaded', function () {
$.fn.DataTable.ext.pager.numbers_length = 7;
var table = $('#{{ $id }}').DataTable({ var table = $('#{{ $id }}').DataTable({
processing: true, processing: true,
serverSide: true, serverSide: true,
ajax: '{{ $ajax }}', ajax: '{{ $ajax }}',
columns: @json($dtColumns), columns: @json($dtColumns),
orderCellsTop: true, orderCellsTop: true,
fixedHeader: true, fixedHeader: false,
pagingType: 'full_numbers', pagingType: 'full_numbers',
language: { language: {
searchPlaceholder: "Search records", processing: '<div class="spinner-border text-primary" role="status" style="width: 2rem; height: 2rem;"><span class="visually-hidden">Loading...</span></div>',
search: "", searchPlaceholder: "Search...",
lengthMenu: "_MENU_", search: "",
}, lengthMenu: "_MENU_",
dom: "<'row'<'col-sm-12'<'table-responsive'tr>>>" + info: "Showing <span class='fw-bold'>_START_</span> to <span class='fw-bold'>_END_</span> of <span class='fw-bold'>_TOTAL_</span> entries",
"<'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>>", paginate: {
initComplete: function () { first: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevrons-left" width="16" height="16"></i></span>',
// Initialize select2 for length menu last: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevrons-right" width="16" height="16"></i></span>',
$('.dataTables_length select').select2({ next: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevron-right" width="16" height="16"></i></span>',
previous: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevron-left" width="16" height="16"></i></span>'
},
zeroRecords: "No matching records found",
emptyTable: "No data available in table"
},
dom: "<'row p-3'<'col-sm-12'tr>>" +
"<'row px-3 pb-3 pt-1 align-items-center'<'col-sm-12 col-md-5 text-muted small'i><'col-sm-12 col-md-7 d-flex align-items-center justify-content-end gap-2'lp>>",
initComplete: function () {
// Initialize select2 with custom styling
$('.dataTables_length select').select2({
minimumResultsForSearch: Infinity, minimumResultsForSearch: Infinity,
width: '60px' width: '80px',
}); dropdownCssClass: 'small-select-dropdown',
selectionCssClass: 'small-select-selection'
// 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();
}
}); });
});
}, // Debounced search for column inputs
drawCallback: function() { this.api().columns().every(function () {
if ($('.dataTables_length select').data('select2')) { var that = this;
$('.dataTables_length select').select2('destroy'); $('input', this.header()).on('keyup change clear', function () {
} if (that.search() !== this.value) {
$('.dataTables_length select').select2({ that.search(this.value).draw();
minimumResultsForSearch: Infinity, }
width: '60px' });
}); });
if (window.lucide) { },
lucide.createIcons(); drawCallback: function () {
// Re-initialize Select2 on draw (if lost)
if ($('.dataTables_length select').data('select2')) {
$('.dataTables_length select').select2('destroy');
}
$('.dataTables_length select').select2({
minimumResultsForSearch: Infinity,
width: '80px'
});
// Re-initialize icons with slight delay to ensuring DOM is ready
setTimeout(function () {
if (window.lucide) {
lucide.createIcons();
}
}, 50);
} }
} });
});
// Prevent sorting when clicking on the input // Prevent sorting when clicking on the input
$('#{{ $id }} thead tr:eq(1) th').on('click', function (e) { $('#{{ $id }} thead tr:eq(1) th').on('click', function (e) {
e.stopPropagation(); e.stopPropagation();
}); });
// Custom search logic for the individual inputs // External trigger for column search (redundant but kept for manual binding if needed)
$('#{{ $id }} .column-search').on('keyup change', function () { $('#{{ $id }} .column-search').on('keyup change', function () {
var columnIndex = $(this).data('column'); var columnIndex = $(this).data('column');
table.column(columnIndex).search(this.value).draw(); table.column(columnIndex).search(this.value).draw();
});
}); });
}); </script>
</script>
@endpush <style>
/* Custom SAAS DataTable Styles */
.data-table-wrapper {
background: #fff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
overflow-y: auto;
position: relative;
}
.pagination button.page-link {
height: 100%;
}
.data-table-wrapper .table thead th {
border-color: #f1f5f9 !important;
font-family: 'Inter', sans-serif;
vertical-align: middle;
position: sticky;
top: 0;
z-index: 5;
background-color: #f8f9fa;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
/* Sticky for second row (filter inputs) if present */
.data-table-wrapper .table thead tr:nth-child(2) th {
top: 45px;
/* Adjust based on typical header height */
z-index: 4;
}
.data-table-wrapper .input-group-text {
color: #94a3b8;
/* Slate 400 */
}
.data-table-wrapper .form-control::placeholder {
color: #cbd5e1;
/* Slate 300 */
}
.dataTables_wrapper .pagination .page-item .page-link {
border: 1px solid transparent;
border-radius: 6px;
margin: 0 2px;
color: #64748b;
padding: 0;
font-size: 0.875rem;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
height: 38px;
min-width: 38px;
}
.dataTables_wrapper .pagination .page-item.active .page-link {
background-color: #0f172a;
/* Slate 900 or Primary Color */
color: white;
font-weight: 500;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-color: #0f172a;
}
.dataTables_wrapper .pagination .page-item.disabled .page-link {
color: #cbd5e1;
background-color: transparent;
}
.dataTables_wrapper .pagination .page-item:not(.active) .page-link:hover {
background-color: #f8fafc;
color: #0f172a;
border-color: #e2e8f0;
}
/* Select2 Customization for Table Length */
.dataTables_length {
margin-right: 1rem;
}
.select2-container--default .select2-selection--single {
border: 1px solid #e2e8f0;
border-radius: 6px;
height: 32px;
display: flex;
align-items: center;
outline: none;
}
.select2-container--default .select2-selection--single:focus {
border-color: #94a3b8;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height: 30px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
color: #475569;
font-size: 0.8125rem;
padding-left: 10px;
line-height: normal;
}
/* Processing Indicator with improved look - Centered */
div.dataTables_processing {
position: absolute;
top: 50% !important;
left: 50% !important;
transform: translate(-50%, -50%);
width: auto !important;
margin: 0 !important;
padding: 1rem 2rem;
text-align: center;
font-size: 1.2em;
background: rgba(255, 255, 255, 0.9);
border-radius: 8px;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
z-index: 100;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #e2e8f0;
color: #0f172a;
}
</style>
@endpush