Skip to content

Commit

Permalink
fix: data table paging
Browse files Browse the repository at this point in the history
we were using did-update on a getter before, which broke with a recent
update.
  • Loading branch information
czosel committed Nov 1, 2021
1 parent 6428909 commit 41896b7
Show file tree
Hide file tree
Showing 3 changed files with 1,639 additions and 1,389 deletions.
5 changes: 2 additions & 3 deletions addon/components/data-table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<table
class="uk-animation-fade uk-table uk-table-divider"
{{did-insert (perform this.fetchData)}}
{{did-update (perform this.fetchData) this.page this.search}}
...attributes
>
{{#if this.isLoading}}
Expand Down Expand Up @@ -59,7 +58,7 @@
<button
type="button"
class="no-style-button"
{{on "click" (set this.page this.previousPage)}}
{{on "click" (fn this.updatePage this.previousPage)}}
>
<span
class="uk-margin-small-right"
Expand All @@ -80,7 +79,7 @@
<button
type="button"
class="no-style-button"
{{on "click" (set this.page this.nextPage)}}
{{on "click" (fn this.updatePage this.nextPage)}}
>
{{t "emeis.pagination.next"}}
<span class="uk-margin-small-left" uk-pagination-next></span>
Expand Down
19 changes: 12 additions & 7 deletions addon/components/data-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@ export default class DataTableComponent extends Component {
get page() {
return this.args.page || this.internalPage;
}
set page(page) {
if (this.args.updatePage) {
this.args.updatePage(page);
} else {
this.internalPage = page;
}
}

get search() {
return this.args.search || this.internalSearch;
}

set search(search) {
if (this.args.updateSearch) {
this.args.updateSearch(search);
Expand Down Expand Up @@ -84,5 +78,16 @@ export default class DataTableComponent extends Component {
// Prevent reaload because of form submit
submitEvent.preventDefault();
this.search = submitEvent.target.elements.search.value;
this.fetchData.perform();
}

@action
updatePage(page) {
if (this.args.updatePage) {
this.args.updatePage(page);
} else {
this.internalPage = page;
}
this.fetchData.perform();
}
}
Loading

0 comments on commit 41896b7

Please sign in to comment.