Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(data-table): always include page query param #544

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions addon/components/data-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,16 @@ export default class DataTableComponent extends Component {
includes = this.args.include.join(",");
}

let options = {
const options = {
include: includes,
filter: { search: this.search, ...(this.args.filter || {}) },
sort: this.sort,
include: includes,
page: {
number: this.page,
size: this.emeisOptions.pageSize,
},
};

if (!this.search) {
options = {
...options,
page: {
number: this.page,
size: this.emeisOptions.pageSize,
},
};
}

const data = yield this.store.query(this.args.modelName, options);
this.numPages = data.meta.pagination?.pages;
this.entryCount = data.meta.pagination?.count;
Expand Down Expand Up @@ -152,6 +146,8 @@ export default class DataTableComponent extends Component {
// Prevent reload because of form submit
submitEvent.preventDefault();
this.search = submitEvent.target.elements.search.value;
// changing search may change the number of pages, therefore navigate to first page
this.page = 1;
}

@action
Expand Down