@@ -470,10 +470,21 @@ describe('ZvTable', () => {
470470 it ( 'should update state when filter changes' , fakeAsync ( ( ) => {
471471 const table = createTableInstance ( true ) ;
472472 spyOn ( table as any , 'requestUpdate' ) . and . callThrough ( ) ;
473+
474+ // Set initial page to verify it gets reset
475+ table . pageIndex = 5 ;
476+
473477 table . onSearchChanged ( 'test' ) ;
478+
474479 expect ( ( table as any ) . requestUpdate ) . toHaveBeenCalledTimes ( 1 ) ;
480+ expect ( ( table as any ) . requestUpdate ) . toHaveBeenCalledWith ( {
481+ searchText : 'test' ,
482+ currentPage : 0 ,
483+ } ) ;
484+
475485 tick ( 1 ) ;
476486 expect ( table . filterText ) . toEqual ( 'test' ) ;
487+ expect ( table . pageIndex ) . toEqual ( 0 ) ;
477488 } ) ) ;
478489
479490 it ( 'should update state when page changes and emit output' , fakeAsync ( ( ) => {
@@ -727,6 +738,40 @@ describe('ZvTable', () => {
727738 expect ( component . table . onSearchChanged ) . toHaveBeenCalledWith ( 'asdf' ) ;
728739 } ) ;
729740
741+ it ( 'should reset page to 0 when filtering' , async ( ) => {
742+ // Initialize with a data source that has enough data for multiple pages
743+ await initTestComponent (
744+ new ZvTableDataSource ( {
745+ loadDataFn : ( ) => of ( Array . from ( { length : 10 } , ( _ , i : number ) => ( { id : i , str : `item ${ i } ` } ) ) ) ,
746+ mode : 'client' ,
747+ } ) ,
748+ ( settingService ) => {
749+ settingService . settings$ . next ( {
750+ [ component . tableId ] : {
751+ pageSize : 3 , // This will create multiple pages
752+ sortColumn : null ,
753+ sortDirection : null ,
754+ columnBlacklist : [ ] ,
755+ } ,
756+ } ) ;
757+ }
758+ ) ;
759+
760+ // Set the page to 2 manually to simulate navigation
761+ component . table . pageIndex = 1 ;
762+ fixture . detectChanges ( ) ;
763+
764+ // Verify we're on page 2
765+ expect ( component . table . pageIndex ) . toEqual ( 1 ) ;
766+
767+ // Apply a filter
768+ const searchInput = await table . getSearchInput ( ) ;
769+ await searchInput . setValue ( 'item' ) ;
770+
771+ // Verify that the page index is reset to 0
772+ expect ( component . table . pageIndex ) . toEqual ( 0 ) ;
773+ } ) ;
774+
730775 it ( 'should sort via dropdown' , async ( ) => {
731776 const sort = await loader . getHarness ( MatSortHarness ) ;
732777 expect ( await sort . getActiveHeader ( ) ) . toBeFalsy ( ) ;
0 commit comments