From 3b1beef66ef64b1b0833f55483cfc4b0c16c160e Mon Sep 17 00:00:00 2001 From: pbao9 Date: Thu, 12 Feb 2026 08:22:39 +0700 Subject: [PATCH] refactor: move product category sub-group datatable rendering from client-side JavaScript to a dedicated server-side Blade partial. --- .../product/ProductCategoryController.php | 8 +++- .../categories/datatable/sub_group.blade.php | 41 +++++++++++++++++++ .../pages/product/categories/index.blade.php | 40 +----------------- 3 files changed, 49 insertions(+), 40 deletions(-) create mode 100644 resources/views/administrator/pages/product/categories/datatable/sub_group.blade.php diff --git a/app/Http/Controllers/admin/product/ProductCategoryController.php b/app/Http/Controllers/admin/product/ProductCategoryController.php index 7a5fd30..a75f01a 100644 --- a/app/Http/Controllers/admin/product/ProductCategoryController.php +++ b/app/Http/Controllers/admin/product/ProductCategoryController.php @@ -123,7 +123,13 @@ class ProductCategoryController extends Controller return '
'; } ) - ->rawColumns(['details_control', 'action', 'is_active', 'checkbox']) + ->addColumn( + 'sub_group_html', + function ($d) { + return view('administrator.pages.product.categories.datatable.sub_group', ['children' => $d->children])->render(); + } + ) + ->rawColumns(['details_control', 'action', 'is_active', 'checkbox', 'sub_group_html']) ->make(true); } } \ No newline at end of file diff --git a/resources/views/administrator/pages/product/categories/datatable/sub_group.blade.php b/resources/views/administrator/pages/product/categories/datatable/sub_group.blade.php new file mode 100644 index 0000000..7c3658c --- /dev/null +++ b/resources/views/administrator/pages/product/categories/datatable/sub_group.blade.php @@ -0,0 +1,41 @@ +@php + use App\Enums\Status; +@endphp + + +@if($children->isNotEmpty()) +
+
Sub Group
+ + + + + + + + + + + @foreach ($children as $child) + + + + + + + @endforeach + +
GroupSlugStatusAction
{{ $child->name }}{{ $child->slug }} + + {{ $child->is_active ? Status::ACTIVE->label() : Status::DEACTIVE->label() }} + + +
+ + + +
+
+
+@endif diff --git a/resources/views/administrator/pages/product/categories/index.blade.php b/resources/views/administrator/pages/product/categories/index.blade.php index d100ed6..d66c2f6 100644 --- a/resources/views/administrator/pages/product/categories/index.blade.php +++ b/resources/views/administrator/pages/product/categories/index.blade.php @@ -82,12 +82,10 @@ $tabs = [ lucide.createIcons(); } - // Disable double click on rows to prevent unwanted editing $('#productTable tbody').off('dblclick'); }, 100); }); - // Child Row (Details Control) Handler var tableId = '#productTable'; $(tableId + ' tbody').on('click', 'td.details-control', function () { var tr = $(this).closest('tr'); @@ -115,49 +113,13 @@ $tabs = [ } } - // Re-init icons for the newly added markup (plus/minus) if (typeof lucide !== 'undefined') { lucide.createIcons(); } }); function format(d) { - // `d` is the original data object for the row - if (!d.children || d.children.length === 0) { - return ''; - } - - var childHtml = '
'; - childHtml += '
Sub Categories
'; - childHtml += ''; - childHtml += ''; - childHtml += ''; - - d.children.forEach(function (child) { - // Re-use logic for status badge if possible, or simple text for now - var statusBadge = child.is_active ? - 'Active' : - 'Inactive'; - - // Build Action Buttons (Edit/Delete) - var editUrl = '{{ route("products.group.edit", ":id") }}'.replace(':id', child.id); - var actionButtons = ` -
- - - -
- `; - childHtml += '' + - '' + - '' + - '' + - '' + - ''; - }); - - childHtml += '
GroupSlugStatusAction
' + child.name + '' + child.slug + '' + statusBadge + '' + actionButtons + '
'; - return childHtml; + return d.sub_group_html; } });