diff --git a/ignite-template.js b/ignite-template.js index 8ad00c6..97ee2fb 100644 --- a/ignite-template.js +++ b/ignite-template.js @@ -1414,7 +1414,7 @@ class IgniteTemplate { * Constructs this template and adds it to the DOM if this template * has not already been constructed. * @param {HTMLElement} parent Parent element that will contain the constructed element. - * @param {HTMLElement} sibling Optional sibling element that can be used to add the element adjacantly. + * @param {HTMLElement} sibling Optional sibling element that when set inserts this element after it. */ construct(parent, sibling) { //Don't construct if we have no parent, no sibling and no element. @@ -3337,7 +3337,7 @@ class pagination extends IgniteTemplate { //Adjust the current page if it's now incorrect. if (this.currentPage >= pages) { - this.currentPage = pages - 1; + this.currentPage = Math.max(0, pages - 1); } //Show the elements in the current page @@ -3401,10 +3401,12 @@ class pagination extends IgniteTemplate { //Construct all the items in our list and use the container if (this.list) { + var last = this.element; + for (var i = 0; i < this.list.length; i++) { var template = this.forEach(this.list[i]); - template.construct(parent, this.element); + template.construct(parent, last); var page = parseInt(i / this.pageSize); if (page != this.currentPage) { @@ -3416,6 +3418,7 @@ class pagination extends IgniteTemplate { this.pages[page].push(template.element); this.children.push(template); this.elements.push(template.element); + last = template.element; } } } @@ -3464,16 +3467,20 @@ class pagination extends IgniteTemplate { IgniteRendering.enter(); try { + var last = this.element; + items.forEach(item => { var template = this.forEach(item); - template.construct(this.element.parentElement, this.element); + template.construct(this.element.parentElement, last); template.element.style.setProperty("display", "none", "important"); this.children.push(template); this.elements.push(template.element); + + last = template.element; }); //Recalculate the pagination. @@ -3563,7 +3570,7 @@ class pagination extends IgniteTemplate { if (this.elements.length > 0) { template.construct(this.element.parentElement, this.elements[start]); } else { - template.construct(this.element.parentElement, null); + template.construct(this.element.parentElement, this.element); } template.element.style.setProperty("display", "none", "important");