AddThisFeature

Sort Controls

Let users choose the order, and keep that order stable.

moderate Search & Discovery

What it adds

Sortable columns and sort menus whose order is deterministic, shareable in the URL, and safe against injected field names.

What your agent is told to do

5
  1. 1

    Define an explicit allowlist of sortable fields and map incoming sort parameters through it. Anything not on the list falls back to the default.

  2. 2

    Always append a unique tie-breaker, such as the primary key, to every sort. Without it, records with equal values reshuffle between pages and users see duplicates and gaps.

  3. 3

    Put the active sort field and direction in the URL so the view can be shared, bookmarked, and restored on back-navigation.

  4. 4

    Decide where nulls and blanks go and apply that decision everywhere — missing values should not silently land at whichever end the database prefers.

  5. 5

    Do NOT interpolate a client-supplied field or direction into a query. That is a direct injection path, and an allowlist costs nothing.

Edge cases it handles

6
  • Text sorting must be case-insensitive and locale-aware, or lowercase entries pile up after uppercase ones.
  • Numbers stored as strings sort as strings. Cast, or store them as numbers.
  • Changing the sort must reset to page one; keeping the offset lands the user mid-list in a different order.
  • A sort over a computed or joined value needs an index, or it will quietly become a full table scan.
  • The active sort and direction must be exposed to assistive tech via aria-sort, not by an arrow glyph alone.
  • The default sort must be explicit. 'Whatever the database returns' is not an order and will change.

Definition of done

8
  • Only allowlisted fields can be sorted; unknown values fall back to the default.
  • Every sort includes a unique tie-breaker and paginates without repeats or gaps.
  • Sort state is in the URL and restores on reload and back-navigation.
  • Null and blank placement is consistent and documented.
  • Changing sort returns to the first page.
  • Sortable headers expose their state through aria-sort.
  • The feature matches the existing design system.
  • No existing functionality is broken.

Related features

How it works

  1. 1

    Copy the link

    Grab the Markdown instruction URL for this feature.

  2. 2

    Give it to your AI

    Paste it into Claude Code, Cursor, v0, Lovable — whatever you build with.

  3. 3

    It inspects, then implements

    Your agent reads your existing app first, then adds the feature to fit it.

Works with your stack

These instructions are written to adapt. They tell the agent to detect your framework, match your existing design system, and reuse what you already have — rather than assuming a particular stack.

Need it tighter than that? Customize the feature and tell it exactly what you're running.