OrderBySelect is an auto-generated component for selecting sort criteria in list pages. Itβs generated based on the backendβs OrderBy enum with auto-mapped labels.
Core Features
Auto-generated
Auto-generated from Entity definitionOrderBy enum based
Localized Labels
Auto label mappingβID Latestβ, βCreated Ascendingβ, etc.
useListParams Integration
register pattern supportAuto URL sync
Customizable
Scaffolding fileFreely modifiable
Auto-generation Conditions
OrderBySelect is auto-generated when theOrderBy enum is defined in the backend.
Backend Definition
Auto-generated Files
Location:web/src/components/user/UserOrderBySelect.tsx
Auto-generated labels: web/src/services/sonamu.generated.ts
Label Generation Rules
id-descβ βID Latestβcreated_at-ascβ βCreated Oldestβusername-descβ βName Descendingβ
asc/desc).Basic Usage
Using with useListParams
- User selects sort option
register("orderBy")automatically updates URLlistParams.orderByis passed when calling API- Backend applies sorting
Props
Basic Usage (without register)
Props Details
placeholder
Text displayed when nothing is selected.textPrefix
Prefix added before each option.textPrefix Use CaseUseful when you want to clearly display current sort at the top of list pages:
clearable
Adds an βAllβ option to reset sorting.- Want to return to default sorting
- Want to see data in database order without sorting
disabled
Disables the component.className
Add Tailwind CSS classes.Real-world Examples
Complete List Filter
Mobile Responsive
Display Number of Sort Options
Customization
OrderBySelect is a scaffolding file, so you can modify it freely.Change Labels
Add Icons
Hide Specific Options
Grouping
Backend Processing
The value selected in OrderBySelect is passed to the backend for actual sorting.Handling in Model
exhaustive Pattern
exhaustive() validates at compile time that all cases are handled.
Regeneration
OrderBySelect is not auto-regenerated after initial generation.When Regeneration is Needed
- Component file was deleted
- Entityβs OrderBy enum significantly changed
Regeneration Method
Troubleshooting
OrderBySelect Not Generated
Cause:OrderBy enum not defined in backend
Solution:
Labels Not Showing in Localized Language
Cause:sonamu.generated.ts not regenerated
Solution:
Sorting Not Applied Despite Selection
Cause:orderBy handling missing in backend Model
Solution: Handle params.orderBy in user.model.tsβs findMany.
Related Documentation
- auto-generated-overview - Auto-generated components overview
- SearchFieldSelect - Search field selection
- useListParams - List filtering hook