Part 1: TreeGroupEditor.vue - Revisions
The logic in your component is sound, but the template for rendering icons can be simplified to fix the visual glitches and make it more robust.
Here is the revised, pasteable code for TreeGroupEditor.vue.
Part 2: Documentation on Usage and Event Handling
This documentation explains how a parent Vue page should use theSidebarTreeTable component, handle its events, and manage the CRUD modals for the sidebar tree.
Documentation: Implementing the SidebarTreeTable Component
TheSidebarTreeTable component is a high-level “smart” component that orchestrates a master-detail view. The parent page is responsible for providing the data-fetching logic and handling the CRUD events emitted by the component.
Use Case Overview
- Sidebar (
TreeGroupEditor): Displays a hierarchical tree of “Categories”. This data is fetched from a dedicated options endpoint (e.g.,/api/category/get-option-tree). Users can select, add, edit, and delete categories. - Main Content (
MejikDatatable): Displays a paginated, sortable, and filterable table of “Articles”. The data shown is filtered based on the category selected in the sidebar. This data comes from the main datatable endpoint (e.g.,/api/article/index).
Parent Page Setup
Your parent Vue component (e.g.,ArticleManager.vue) will look like this:
Event Handling in the Parent Component
The parent’s<script> section is where you implement the logic to respond to events from SidebarTreeTable.
1. Data Loading (loader prop)
The most important prop is loader. You must provide a function that knows how to fetch the datatable’s data. SidebarTreeTable will call this function whenever the table needs to be refreshed (e.g., on page change, sort, or category selection).
2. Handling Tree CRUD Events
SidebarTreeTable bubbles up events from the TreeGroupEditor. You listen for these events to trigger your modals and API calls.
Example Implementation:
this.$refs.sidebarTree.fetchTree() work, add ref="sidebarTree" to your <SidebarTreeTable> component in the template.
Dokumentasi (Bahasa Indonesia)
Dokumentasi: Implementasi Komponen SidebarTreeTable
KomponenSidebarTreeTable adalah komponen “pintar” tingkat tinggi yang mengatur tampilan master-detail. Halaman induk bertanggung jawab untuk menyediakan logika pengambilan data dan menangani event CRUD yang di-emit oleh komponen.
Gambaran Studi Kasus
- Sidebar (
TreeGroupEditor): Menampilkan pohon hierarki “Kategori”. Data ini diambil dari endpoint opsi khusus (misal,/api/category/get-option-tree). Pengguna dapat memilih, menambah, mengedit, dan menghapus kategori. - Konten Utama (
MejikDatatable): Menampilkan tabel “Artikel” yang terpaginasi, dapat diurutkan, dan difilter. Data yang ditampilkan difilter berdasarkan kategori yang dipilih di sidebar. Data ini berasal dari endpoint datatable utama (misal,/api/article/index).
Pengaturan Halaman Induk
Komponen Vue induk Anda (misalnya,ArticleManager.vue) akan terlihat seperti ini:
Penanganan Event di Komponen Induk
Bagian<script> dari komponen induk adalah tempat Anda mengimplementasikan logika untuk merespons event dari SidebarTreeTable.
1. Pemuatan Data (prop loader)
Prop terpenting adalah loader. Anda harus menyediakan sebuah fungsi yang tahu cara mengambil data datatable. SidebarTreeTable akan memanggil fungsi ini setiap kali tabel perlu diperbarui (misalnya, saat ganti halaman, mengurutkan, atau memilih kategori).
2. Menangani Event CRUD Pohon Data
SidebarTreeTable meneruskan event dari TreeGroupEditor. Anda mendengarkan event-event ini untuk memicu modal dan panggilan API Anda.
Contoh Implementasi:
this.$refs.sidebarTree.fetchTree() berfungsi, tambahkan ref="sidebarTree" pada komponen <SidebarTreeTable> di dalam template Anda.