@@ -21,7 +21,7 @@ class BaseModelBrowser extends Component
2121
2222 public const PER_PAGE_MIN = 3 ;
2323 public const PER_PAGE_MAX = 150 ;
24- public const PER_PAGE_DEFAULT = 50 ;
24+ public const PER_PAGE_DEFAULT = 20 ;
2525
2626 #[Locked]
2727 public string $ model ;
@@ -177,33 +177,37 @@ protected function getData(bool $paginate = true, bool $highlightMatches = true,
177177 }
178178 }
179179
180- if ($ applyFormats ) {
180+ $ applyFormatsOnAll = ! empty ($ this ->filterAttributes ) || $ this ->enableSort ;
181+
182+ if ($ applyFormats && $ applyFormatsOnAll ) {
181183 $ data = $ this ->format ($ data );
182184 }
183185
184- if ($ this ->filter ) {
186+ if (! empty ( $ this -> filterAttributes ) && $ this ->filter ) {
185187 $ data = $ this ->applyFilter ($ data );
186188 }
187189
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+ }
193197 }
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+ }
204208 }
209+ $ data = $ data ->sortBy ($ sortByArg );
205210 }
206- $ data = $ data ->sortBy ($ sortByArg );
207211 }
208212
209213 // Paginate manually if required
@@ -222,6 +226,17 @@ protected function getData(bool $paginate = true, bool $highlightMatches = true,
222226 }
223227 }
224228
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+
225240 if ($ highlightMatches ) {
226241 $ highlightedColumns = $ this ->filterColumn == 'all ' ? $ this ->filterAttributes : [$ this ->filterColumn ];
227242 if ($ paginate ) {
0 commit comments