You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -397,6 +397,27 @@ class CategoryTree extends TreePage
397
397
}
398
398
```
399
399
400
+
### Customizing Data Display in Tree Widgets
401
+
402
+
For advanced use cases, you may want to limit or customize the data displayed in your tree widget: for example, showing only items matching specific criteria or related to a parent resource.
403
+
404
+
You can achieve this by overriding the getTreeQuery method in your widget, allowing full control over the Eloquent query used to fetch records.
405
+
406
+
```php
407
+
use App\Models\Menuitem;
408
+
use Illuminate\Database\Eloquent\Builder;
409
+
class MenuItemsWidget extends Tree
410
+
{
411
+
// Accessing the current record in the widget
412
+
public ?Model $record = null;
413
+
414
+
protected function getTreeQuery(): Builder
415
+
{
416
+
return MenuItem::query()
417
+
->where('menu_id', $this->record?->id); // Filter by the current menu ID
418
+
}
419
+
```
420
+
400
421
### Custom Column Names
401
422
402
423
Override default column names if your table structure differs:
0 commit comments