Skip to content

Commit

Permalink
fix(data-table): always include page meta info (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabauke authored Aug 8, 2022
1 parent e62452d commit 43c6a28
Showing 1 changed file with 8 additions and 12 deletions.
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

0 comments on commit 43c6a28

Please sign in to comment.