Skip to content

Sort the invoice customer dropdown alphabetically - #141

Merged
kittendevv merged 1 commit into
kittendevv:mainfrom
davidbucka:sort-customers-alphabetically
Sep 7, 2026
Merged

Sort the invoice customer dropdown alphabetically#141
kittendevv merged 1 commit into
kittendevv:mainfrom
davidbucka:sort-customers-alphabetically

Conversation

@davidbucka

@davidbucka davidbucka commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #131

Problem

/api/v1/customers returns rows ORDER BY created_at DESC, and InvoiceEditor.svelte renders that order straight into the customer <select>. On both /invoices/new and /invoices/[id]/edit the dropdown is therefore ordered newest-first, which gets harder to scan as the customer list grows.

Change

One file. The customers derived value in InvoiceEditor.svelte now sorts a copy of the list by name, using the same localeCompare options the invoice table already uses in routes/invoices/+page.svelte:

String(a?.name || "").localeCompare(String(b?.name || ""), undefined, {
  numeric: true,
  sensitivity: "base",
})

Sorting client-side rather than in the SQL keeps the change scoped to the dropdown the issue is about. Changing ORDER BY in controllers/customers.ts would also flip the /customers listing away from newest-first, and SQLite COLLATE NOCASE is ASCII-only, so accented names would sort after Z. Happy to move it into the query instead if you would rather have it apply everywhere.

Testing

Ran the backend and the SvelteKit dev server locally with seven customers created in deliberately non-alphabetical order.

Before:

Charlie & Co, Ökotec Berlin, Ärzte Zentrum Nord, Beta Ltd, Müller AG, alpha services, Zeppelin GmbH

After:

alpha services, Ärzte Zentrum Nord, Beta Ltd, Charlie & Co, Müller AG, Ökotec Berlin, Zeppelin GmbH

Casing is ignored, so alpha services sorts first rather than last, and Ä/Ö sort next to A/O.

Also checked on /invoices/[id]/edit that the list is sorted while the invoice's existing customer stays preselected, and that picking a different customer from the sorted dropdown saves correctly.

bun run check reports 0 errors, eslint is clean, and bun run build succeeds. prettier --check flags the same 5 files it already flags on an unmodified main; the changed file passes.

The customers endpoint returns rows in creation order, and the invoice
editor rendered that order straight into the select, so the list got
harder to scan as it grew.

Sort by name with localeCompare using the same numeric/base-sensitivity
options the invoice table already uses, so casing is ignored and accented
names sort next to their base letter rather than after Z.

Fixes kittendevv#131

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kittendevv
kittendevv merged commit 1b2f804 into kittendevv:main Sep 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sort customer list alphabetically when creating an invoice

2 participants