diff --git a/src/lib/ae_events/ae_events__event_badge.ts b/src/lib/ae_events/ae_events__event_badge.ts index 9a4ea9c2..6929604a 100644 --- a/src/lib/ae_events/ae_events__event_badge.ts +++ b/src/lib/ae_events/ae_events__event_badge.ts @@ -466,7 +466,7 @@ export async function search__event_badge({ log_lvl?: number; }) { if (log_lvl) { - console.log(`*** search__event_badge() *** event_id=${event_id} printed_status=${printed_status} affiliations=${affiliations_qry_str}`); + console.log(`*** search__event_badge() *** event_id=${event_id} printed_status=${printed_status} affiliations=${affiliations_qry_str} order_by_li=`, order_by_li); } if (!fulltext_search_qry_str && !like_search_qry_str && !affiliations_qry_str && !type_code && !external_event_id && printed_status === 'all') { @@ -633,6 +633,8 @@ export const properties_to_save = [ 'updated_on', 'print_count', + 'print_first_datetime', + 'print_last_datetime', // Generated fields for sorting locally only 'tmp_sort_1', diff --git a/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_obj_li.svelte b/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_obj_li.svelte index 2195fbcc..b56c1983 100644 --- a/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_obj_li.svelte +++ b/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_obj_li.svelte @@ -24,6 +24,7 @@ import { liveQuery } from 'dexie'; import { db_events, type Badge } from '$lib/ae_events/db_events'; import { ae_loc } from '$lib/stores/ae_stores'; + import { ae_util } from '$lib/ae_utils/ae_utils'; // let trusted_access = $derived(ae_loc.trusted_access); // This does NOT work with Svelte v5 // let trusted_access = $ae_loc?.trusted_access; // This works with Svelte v5 @@ -31,7 +32,16 @@ liveQuery(async () => { if (badge_obj_li?.length) { const ids = badge_obj_li.map((b) => b.event_badge_id_random); - return await db_events.badge.bulkGet(ids); + const db_results = await db_events.badge.bulkGet(ids); + + // Create a map for quick lookup by ID to restore order + // bulkGet does not guarantee order, so we must re-sort based on the input list + const db_results_map = new Map( + db_results.filter(Boolean).map((item) => [item.event_badge_id_random, item]) + ); + + // Return items in the exact order of the original 'ids' array + return ids.map((id) => db_results_map.get(id)).filter(Boolean); } return []; }) @@ -51,114 +61,157 @@ -