Skip to main content
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 the OrderBy 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”
Generated by combining field name and sort direction (asc/desc).

Basic Usage

Using with useListParams

How it works:
  1. User selects sort option
  2. register("orderBy") automatically updates URL
  3. listParams.orderBy is passed when calling API
  4. 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.
Use scenarios:
  • 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

  1. Component file was deleted
  2. Entity’s OrderBy enum significantly changed

Regeneration Method

Caution on RegenerationCustomized content will be lost on regeneration. Back up or document important modifications separately.

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.