I have a contacts table which is infinitely scrolled via .paginate. There is a search bar users can search by name for.
Query:
export async function paginate(
ctx: QueryCtx,
args: {
firmId: Id<"firms">;
paginationOpts: PaginationOpts;
searchTerm?: string;
},
) {
const { firmId, searchTerm } = args;
const term = searchTerm?.toLowerCase().trim();
return filter(
ctx.db
.query("contacts")
.withIndex("firmId_deletedAt", (q) =>
q.eq("firmId", firmId).eq("deletedAt", undefined),
),
(contact) => {
if (!term) return true;
return contact.name.toLowerCase().includes(term);
},
)
.order("desc")
.paginate(args.paginationOpts);
// calling
export const paginate = queryWithAuth({
args: {
paginationOpts: paginationOptsValidator,
searchTerm: v.optional(v.string()),
},
handler: async (ctx, args) => {
return Contacts.paginate(ctx, { ...args, firmId: ctx.user.firmId });
},
});
// Call in UI:
const {
results: contacts,
status,
loadMore,
} = usePaginatedQuery(
api.queries.contacts.paginate,
{ searchTerm: filter.searchTerm ?? undefined },
{ initialNumItems: 50 },
);
}```
When i filter for names that are on the first page, theres 150 total entries, and i display 50 per page, it will successfully return a match. But if I search for the name of the last record in the table "Emma Thompson", the query returns no results. Why is this?