Skip to content

Commit ecce4a5

Browse files
YiricaMichael Dorr
andauthored
UPCORE-1122 (table) Search on page out of result scope produces issues (#33)
Co-authored-by: Michael Dorr <michael.dorr@zvoove.com>
1 parent 8ac13fe commit ecce4a5

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

projects/components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zvoove/components",
33
"description": "A set of angular components compatible with and/or dependent on @angular/material.",
4-
"version": "19.3.0",
4+
"version": "19.3.1",
55
"license": "MIT",
66
"repository": {
77
"type": "git",

projects/components/table/src/table.component.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

projects/components/table/src/table.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export class ZvTable<TData = unknown> implements OnInit, OnChanges, AfterContent
274274
public onSearchChanged(value: string | null) {
275275
this.requestUpdate({
276276
searchText: value,
277+
currentPage: 0,
277278
});
278279
}
279280

0 commit comments

Comments
 (0)