@@ -21,7 +21,7 @@ class BaseModelBrowser extends Component
21
21
22
22
public const PER_PAGE_MIN = 3 ;
23
23
public const PER_PAGE_MAX = 150 ;
24
- public const PER_PAGE_DEFAULT = 50 ;
24
+ public const PER_PAGE_DEFAULT = 20 ;
25
25
26
26
#[Locked]
27
27
public string $ model ;
@@ -177,33 +177,37 @@ protected function getData(bool $paginate = true, bool $highlightMatches = true,
177
177
}
178
178
}
179
179
180
- if ($ applyFormats ) {
180
+ $ applyFormatsOnAll = ! empty ($ this ->filterAttributes ) || $ this ->enableSort ;
181
+
182
+ if ($ applyFormats && $ applyFormatsOnAll ) {
181
183
$ data = $ this ->format ($ data );
182
184
}
183
185
184
- if ($ this ->filter ) {
186
+ if (! empty ( $ this -> filterAttributes ) && $ this ->filter ) {
185
187
$ data = $ this ->applyFilter ($ data );
186
188
}
187
189
188
- // Multi-column sort
189
- $ sort = $ this ->sort ;
190
- foreach ($ this ->defaultSort as $ attribute => $ direction ) {
191
- if (! isset ($ sort [$ attribute ])) {
192
- $ sort [$ attribute ] = $ direction ;
190
+ if ($ this ->enableSort ) {
191
+ // Multi-column sort
192
+ $ sort = $ this ->sort ;
193
+ foreach ($ this ->defaultSort as $ attribute => $ direction ) {
194
+ if (! isset ($ sort [$ attribute ])) {
195
+ $ sort [$ attribute ] = $ direction ;
196
+ }
193
197
}
194
- }
195
- if (! empty ( $ sort )) {
196
- $ sortByArg = [];
197
- foreach ( $ sort as $ attribute => $ direction ) {
198
- if ( is_callable ( $ this ->sortComparators [$ attribute ][$ direction ] ?? null )) {
199
- $ sortByArg [] = Closure:: fromCallable ( $ this -> sortComparators [ $ attribute ][ $ direction ]);
200
- } else {
201
- $ sortByArg [] = fn ( $ a , $ b ) => $ direction === ' desc '
202
- ? str ($ this ->itemValueStripped ($ b , $ attribute ))->ascii () <=> str ($ this ->itemValueStripped ($ a , $ attribute ))->ascii ()
203
- : str ( $ this -> itemValueStripped ( $ a , $ attribute ))-> ascii () <=> str ( $ this -> itemValueStripped ( $ b , $ attribute ))-> ascii ();
198
+ if (! empty ( $ sort )) {
199
+ $ sortByArg = [];
200
+ foreach ( $ sort as $ attribute => $ direction ) {
201
+ if ( is_callable ( $ this -> sortComparators [ $ attribute ][ $ direction] ?? null ) ) {
202
+ $ sortByArg [] = Closure:: fromCallable ( $ this ->sortComparators [$ attribute ][$ direction ]);
203
+ } else {
204
+ $ sortByArg [] = fn ( $ a , $ b ) => $ direction === ' desc '
205
+ ? str ( $ this -> itemValueStripped ( $ b , $ attribute ))-> ascii () < => str ( $ this -> itemValueStripped ( $ a , $ attribute ))-> ascii ()
206
+ : str ($ this ->itemValueStripped ($ a , $ attribute ))->ascii () <=> str ($ this ->itemValueStripped ($ b , $ attribute ))->ascii ();
207
+ }
204
208
}
209
+ $ data = $ data ->sortBy ($ sortByArg );
205
210
}
206
- $ data = $ data ->sortBy ($ sortByArg );
207
211
}
208
212
209
213
// Paginate manually if required
@@ -222,6 +226,17 @@ protected function getData(bool $paginate = true, bool $highlightMatches = true,
222
226
}
223
227
}
224
228
229
+ if ($ applyFormats && ! $ applyFormatsOnAll ) {
230
+ // Apply formats only to the current page if not applied on all
231
+ if ($ paginate ) {
232
+ $ data ->setCollection (
233
+ $ this ->format ($ data ->getCollection ())
234
+ );
235
+ } else {
236
+ $ data = $ this ->format ($ data );
237
+ }
238
+ }
239
+
225
240
if ($ highlightMatches ) {
226
241
$ highlightedColumns = $ this ->filterColumn == 'all ' ? $ this ->filterAttributes : [$ this ->filterColumn ];
227
242
if ($ paginate ) {
0 commit comments