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 authored and Akanksh Saxena committed Nov 1, 2021
1 parent 6428909 commit 660641b
Show file tree
Hide file tree
Showing 4 changed files with 1,642 additions and 1,390 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();
}
}
4 changes: 3 additions & 1 deletion tests/integration/components/data-table-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ module("Integration | Component | data-table", function (hooks) {
assert.dom("tfoot li:last-child").doesNotHaveClass("uk-disabled");

this.set("page", 2);
await click("[data-test-next-page] button");

assert.dom("tfoot li:first-child").doesNotHaveClass("uk-disabled");
assert.dom("tfoot li:last-child").doesNotHaveClass("uk-disabled");

this.set("page", 3);
await click("[data-test-next-page] button");

assert.dom("tfoot li:first-child").doesNotHaveClass("uk-disabled");
assert.dom("tfoot li:last-child").hasClass("uk-disabled");
Expand Down Expand Up @@ -121,7 +123,7 @@ module("Integration | Component | data-table", function (hooks) {
});

test("external search", async function (assert) {
assert.expect(8);
assert.expect(7);
this.setProperties({
search: undefined,
});
Expand Down
Loading

0 comments on commit 660641b

Please sign in to comment.