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: docs/cookbook/admin_panel/grids.md
+50-84Lines changed: 50 additions & 84 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,10 @@
1
1
# Customizing your grids
2
2
3
-
<divdata-full-width="false">
4
-
5
-
<figure><imgsrc="../../.gitbook/assets/full_talk_grid.png"alt="Overview of an admin dashboard"></figure>
6
-
7
-
</div>
8
-
9
-
<divdata-full-width="false">
3
+
<divdata-full-width="false"><figure><imgsrc="../../.gitbook/assets/full_talk_grid.png"alt="Overview of an admin dashboard"><figcaption></figcaption></figure></div>
10
4
11
5
Based on the grid generated by default, our goal here is to obtain a nicely customized grid with autocomplete filters and more!
12
6
13
-
<figure><imgsrc="../../.gitbook/assets/basic_talk_grid.png"alt="Overview of an admin dashboard"></figure>
14
-
15
-
</div>
7
+
<figure><imgsrc="../../.gitbook/assets/basic_talk_grid.png"alt="Overview of an admin dashboard"><figcaption></figcaption></figure>
16
8
17
9
Let's imagine we have the following grid.
18
10
@@ -34,21 +26,20 @@ use Sylius\Bundle\GridBundle\Builder\Field\DateTimeField;
34
26
use Sylius\Bundle\GridBundle\Builder\Field\StringField;
35
27
use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface;
36
28
use Sylius\Bundle\GridBundle\Grid\AbstractGrid;
37
-
use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface;
29
+
use Sylius\Component\Grid\Attribute\AsGrid;
38
30
39
-
final class TalkGrid extends AbstractGrid implements ResourceAwareGridInterface
31
+
#[AsGrid(
32
+
name: 'app_talk',
33
+
resourceClass: Talk::class,
34
+
)]
35
+
final class TalkGrid extends AbstractGrid
40
36
{
41
37
public function __construct()
42
38
{
43
39
// TODO inject services if required
44
40
}
45
41
46
-
public static function getName(): string
47
-
{
48
-
return 'app_talk';
49
-
}
50
-
51
-
public function buildGrid(GridBuilderInterface $gridBuilder): void
42
+
public function __invoke(GridBuilderInterface $gridBuilder): void
52
43
{
53
44
$gridBuilder
54
45
// see https://github.com/Sylius/SyliusGridBundle/blob/master/docs/field_types.md
@@ -95,22 +86,13 @@ final class TalkGrid extends AbstractGrid implements ResourceAwareGridInterface
95
86
)
96
87
;
97
88
}
98
-
99
-
public function getResourceClass(): string
100
-
{
101
-
return Talk::class;
102
-
}
103
89
}
104
90
```
105
-
{% endcode %}
91
+
{% endcode %}
106
92
107
93
## Fields
108
94
109
-
<divdata-full-width="false">
110
-
111
-
<figure><imgsrc="../../.gitbook/assets/clean_talk_grid.png"alt="Overview of an admin dashboard"></figure>
112
-
113
-
</div>
95
+
<divdata-full-width="false"><figure><imgsrc="../../.gitbook/assets/clean_talk_grid.png"alt="Overview of an admin dashboard"><figcaption></figcaption></figure></div>
114
96
115
97
Let's clean up our grid and remove unnecessary fields.
116
98
@@ -132,16 +114,15 @@ use Sylius\Bundle\GridBundle\Builder\Field\DateTimeField;
132
114
use Sylius\Bundle\GridBundle\Builder\Field\StringField;
133
115
use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface;
134
116
use Sylius\Bundle\GridBundle\Grid\AbstractGrid;
135
-
use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface;
117
+
use Sylius\Component\Grid\Attribute\AsGrid;
136
118
137
-
final class TalkGrid extends AbstractGrid implements ResourceAwareGridInterface
119
+
#[AsGrid(
120
+
name: 'app_talk',
121
+
resourceClass: Talk::class,
122
+
)]
123
+
final class TalkGrid extends AbstractGrid
138
124
{
139
-
public static function getName(): string
140
-
{
141
-
return 'app_talk';
142
-
}
143
-
144
-
public function buildGrid(GridBuilderInterface $gridBuilder): void
125
+
public function __invoke(GridBuilderInterface $gridBuilder): void
145
126
{
146
127
$gridBuilder
147
128
->addField(
@@ -172,30 +153,17 @@ final class TalkGrid extends AbstractGrid implements ResourceAwareGridInterface
172
153
)
173
154
;
174
155
}
175
-
176
-
public function getResourceClass(): string
177
-
{
178
-
return Talk::class;
179
-
}
180
156
}
181
157
```
182
158
{% endcode %}
183
159
184
-
We have removed the "description", "endsAt" and "track" grid fields.
160
+
We have removed the `description`, `endsAt` and `track` grid fields.
185
161
186
-
<divdata-full-width="false">
187
-
188
-
<figure><imgsrc="../../.gitbook/assets/clean_talk_grid.png"alt="Overview of an admin dashboard"></figure>
189
-
190
-
</div>
162
+
<divdata-full-width="false"><figure><imgsrc="../../.gitbook/assets/clean_talk_grid.png"alt="Overview of an admin dashboard"><figcaption></figcaption></figure></div>
191
163
192
164
## Adding the speaker avatar using Twig field
193
165
194
-
<divdata-full-width="false">
195
-
196
-
<figure><imgsrc="../../.gitbook/assets/talk_grid_with_avatar.png"alt="Overview of an admin dashboard"></figure>
197
-
198
-
</div>
166
+
<divdata-full-width="false"><figure><imgsrc="../../.gitbook/assets/talk_grid_with_avatar.png"alt="Overview of an admin dashboard"><figcaption></figcaption></figure></div>
199
167
200
168
Now, let's add the speaker avatar into our talk grid.
201
169
@@ -207,14 +175,18 @@ namespace App\Grid;
207
175
use Sylius\Bundle\GridBundle\Builder\Field\TwigField;
208
176
use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface;
209
177
use Sylius\Bundle\GridBundle\Grid\AbstractGrid;
210
-
use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface;
178
+
use Sylius\Component\Grid\Attribute\AsGrid;
211
179
// ...
212
180
213
-
final class TalkGrid extends AbstractGrid implements ResourceAwareGridInterface
181
+
#[AsGrid(
182
+
name: 'app_talk',
183
+
resourceClass: Talk::class,
184
+
)]
185
+
final class TalkGrid extends AbstractGrid
214
186
{
215
187
// ...
216
188
217
-
public function buildGrid(GridBuilderInterface $gridBuilder): void
189
+
public function __invoke(GridBuilderInterface $gridBuilder): void
218
190
{
219
191
$gridBuilder
220
192
->addField(
@@ -230,22 +202,17 @@ final class TalkGrid extends AbstractGrid implements ResourceAwareGridInterface
230
202
}
231
203
```
232
204
233
-
templates/talk/grid/speaker_avatar.html.twig
234
-
{% import '@SyliusBootstrapAdminUi/shared/helper/avatar.html.twig' as avatar %}
235
-
236
-
{% set avatar_path = data.avatar.path is defined ? vich_uploader_asset(data.avatar) : null %}
<figure><imgsrc="../../.gitbook/assets/autocomplete_filter.png"alt="Overview of an admin dashboard"></figure>
247
-
248
-
</div>
215
+
<divdata-full-width="false"><figure><imgsrc="../../.gitbook/assets/autocomplete_filter.png"alt="Overview of an admin dashboard"><figcaption></figcaption></figure></div>
249
216
250
217
We'd like to filter our talks by a specific speaker.
251
218
@@ -296,11 +263,16 @@ declare(strict_types=1);
296
263
namespace App\Grid\Filter;
297
264
298
265
use App\Form\SpeakerAutocompleteType;
266
+
use Sylius\Component\Grid\Attribute\AsFilter;
299
267
use Sylius\Component\Grid\Data\DataSourceInterface;
300
268
use Sylius\Component\Grid\Filter\EntityFilter;
301
-
use Sylius\Component\Grid\Filtering\ConfigurableFilterInterface;
269
+
use Sylius\Component\Grid\Filtering\FilterInterface;
302
270
303
-
final class SpeakerFilter implements ConfigurableFilterInterface
0 commit comments