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
+70-20Lines changed: 70 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
[](https://packagist.org/packages/codewithdennis/filament-select-tree)
The multi-level select field lets you pick one or multiple options from a list that's neatly organized into different levels. It's all made possible with [TreeSelectJS](https://github.com/dipson88/treeselectjs).
6
+
This is a package that allows you to create an interactive select tree field based on relationships in your Laravel / Filament application. It provides a convenient way to build hierarchical selection dropdowns with various customization options.
- BelongsTo Integration: Establish connections within your data effortlessly.
25
28
- BelongsToMany Integration: Simplify the management of complex relationships through BelongsToMany integration.
26
29
27
-
🐛 One thing I have noticed about this project is that it tends to run a lot of queries, mainly because of its recursive design. Working to fix this in the upcoming updates.
30
+
__🔍 One thing I've noticed is that it runs a lot of queries, mainly because of its recursive design. Working on reducing this in the upcoming updates to make it faster!__
28
31
29
32
## Usage
30
33
34
+
Import the `SelectTree` class from the `CodeWithDennis\FilamentSelectTree` namespace
35
+
31
36
```PHP
32
37
use CodeWithDennis\FilamentSelectTree\SelectTree;
38
+
```
39
+
40
+
Create a tree based on a 'BelongsToMany' relationship
33
41
34
-
// Create a tree based on a 'BelongsToMany' relationship
42
+
```PHP
35
43
SelectTree::make('categories')
36
44
->relationship('categories', 'name', 'parent_id', function ($query) {
37
45
return $query;
38
46
})
47
+
```
48
+
49
+
Create a tree based on a 'BelongsTo' relationship
39
50
40
-
// Create a tree based on a 'BelongsTo' relationship
51
+
```PHP
41
52
SelectTree::make('category_id')
42
53
->relationship('category', 'name', 'parent_id', function ($query) {
43
54
return $query;
44
55
})
56
+
```
57
+
58
+
Set a custom placeholder when no items are selected
59
+
60
+
```PHP
61
+
->placeholder(__('Please select a category'))
62
+
```
45
63
46
-
// Set a custom placeholder when no items are selected
47
-
->placeholder(__('Enter your custom placeholder here'))
64
+
Enable the selection of groups
48
65
49
-
// Enable the selection of groups
66
+
```PHP
50
67
->enableBranchNode()
68
+
```
51
69
52
-
// Customize the label when there are zero search results
53
-
->emptyLabel(__('No results found'))
70
+
Customize the label when there are zero search results
71
+
72
+
```PHP
73
+
->emptyLabel(__('Oops, no results have been found!'))
74
+
```
54
75
55
-
// Display the count of children alongside the group's name
76
+
Display the count of children alongside the group's name
77
+
78
+
```PHP
56
79
->withCount()
80
+
```
57
81
58
-
// Keep the dropdown open at all times
82
+
Keep the dropdown open at all times
83
+
84
+
```PHP
59
85
->alwaysOpen()
86
+
```
60
87
61
-
// Set nodes as dependent
88
+
Set nodes as dependent
89
+
90
+
```PHP
62
91
->independent(false)
92
+
```
63
93
64
-
// Set the parent's null value to -1, allowing you to use -1 as a sentinel value (default = null)
65
-
->parentNullValue(-1)
94
+
Expand the tree with selected values (only works if field is dependent)
66
95
67
-
// Expand the tree with selected values
96
+
```PHP
68
97
->expandSelected(false)
98
+
```
99
+
100
+
Set the parent's null value to -1, allowing you to use -1 as a sentinel value (default = null)
69
101
70
-
// All groups will be opened to this level
102
+
```PHP
103
+
->parentNullValue(-1)
104
+
```
105
+
106
+
All groups will be opened to this level
107
+
108
+
```PHP
71
109
->defaultOpenLevel(2)
110
+
```
111
+
112
+
Specify the list's force direction. Options include: auto (default), top, and bottom.
72
113
73
-
// Specify the list's force direction. Options include: auto (default), top, and bottom.
114
+
```PHP
74
115
->directon('top')
116
+
```
117
+
118
+
Display individual leaf nodes instead of the main group when all leaf nodes are selected
75
119
76
-
// Display individual leaf nodes instead of the main group when all leaf nodes are selected
120
+
```PHP
77
121
->grouped(false)
122
+
```
123
+
124
+
Hide the clearable icon
78
125
79
-
// Hide the clearable icon
126
+
```PHP
80
127
->clearable(false)
128
+
```
129
+
130
+
Activate the search functionality
81
131
82
-
// Activate the search functionality for the SelectTree
0 commit comments