@@ -327,17 +327,24 @@ export function VendorsTable({
327327 const comparison = ( aValue as string ) . localeCompare ( bValue as string ) ;
328328 return sort . desc ? - comparison : comparison ;
329329 }
330- const comparison =
331- new Date ( aValue as Date ) . getTime ( ) - new Date ( bValue as Date ) . getTime ( ) ;
330+ const comparison = new Date ( aValue as Date ) . getTime ( ) - new Date ( bValue as Date ) . getTime ( ) ;
332331 return sort . desc ? - comparison : comparison ;
333332 } ) ;
334333
335334 return result ;
336335 } , [ mergedVendors , searchQuery , sort ] ) ;
337336
338337 // Calculate pageCount from filtered data and paginate
339- const filteredPageCount = Math . max ( 1 , Math . ceil ( filteredAndSortedVendors . length / perPage ) ) ;
340- const startIndex = ( page - 1 ) * perPage ;
338+ // When searching locally, calculate pageCount from filtered data
339+ // When not searching, use server's pageCount (server handles pagination)
340+ const filteredPageCount = searchQuery
341+ ? Math . max ( 1 , Math . ceil ( filteredAndSortedVendors . length / perPage ) )
342+ : Math . max ( 1 , vendorsData ?. pageCount ?? initialPageCount ) ;
343+
344+ // When searching locally, slice the data for client-side pagination
345+ // When not searching, server returns the correct page, but slice to enforce perPage
346+ // (avoids extra rows from onboarding pending/temp vendors)
347+ const startIndex = searchQuery ? ( page - 1 ) * perPage : 0 ;
341348 const paginatedVendors = filteredAndSortedVendors . slice ( startIndex , startIndex + perPage ) ;
342349
343350 // Keep page in bounds when pageCount changes
@@ -358,9 +365,7 @@ export function VendorsTable({
358365 return metadataStatus === 'completed' || vendor . status === 'assessed' ;
359366 } ) . length ;
360367
361- const completedInMetadata = Object . values ( itemStatuses ) . filter (
362- ( s ) => s === 'completed' ,
363- ) . length ;
368+ const completedInMetadata = Object . values ( itemStatuses ) . filter ( ( s ) => s === 'completed' ) . length ;
364369
365370 const total = Math . max ( progress . total , itemsInfo . length , vendors . length ) ;
366371 const completed = Math . max ( completedCount , completedInMetadata ) ;
@@ -420,9 +425,7 @@ export function VendorsTable({
420425 setVendorToDelete ( null ) ;
421426 } else {
422427 const errorMsg =
423- typeof result ?. data ?. error === 'string'
424- ? result . data . error
425- : 'Failed to delete vendor' ;
428+ typeof result ?. data ?. error === 'string' ? result . data . error : 'Failed to delete vendor' ;
426429 toast . error ( errorMsg ) ;
427430 }
428431 } catch {
0 commit comments