Cleaned up code and fixed a few bugs with the pagination code that was messing up with the order of elements when rendering.

This commit is contained in:
2025-06-21 20:37:24 -07:00
parent cd4c5b43d7
commit 80a0e81973

View File

@ -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");