[New] Fixed scrolling after paging

This commit is contained in:
Robert von Burg 2024-02-26 15:58:58 +01:00
parent d9206fc4fa
commit 04cdcbdf59
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
2 changed files with 17 additions and 1 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "strolch-wc-paging", "name": "strolch-wc-paging",
"description": "Strolch WebComponent Paging", "description": "Strolch WebComponent Paging",
"version": "0.2.0", "version": "0.2.1",
"authors": [ "authors": [
"Robert von Burg" "Robert von Burg"
], ],

View File

@ -16,6 +16,10 @@
previousOffset: 0, previousOffset: 0,
lastOffset: 0 lastOffset: 0
} }
},
scrollTarget: {
type: Object,
value: null
} }
}, },
@ -75,6 +79,18 @@
this.ajax.params.limit = this.dataObj.limit; this.ajax.params.limit = this.dataObj.limit;
this.ajax.params.offset = this.dataObj.offset; this.ajax.params.offset = this.dataObj.offset;
this.ajax.generateRequest(); this.ajax.generateRequest();
this.ajax.addEventListener('response', this);
},
handleEvent: function (event) {
if (event.type !== "response")
return;
this.ajax.removeEventListener('response', this);
if (this.scrollTarget != null) {
this.scrollTarget.scrollIntoView({behavior: "smooth", block: "start", inline: "start"});
} else {
window.scrollTo({top: 0, left: 0, behavior: "smooth"});
}
} }
}; };
</script> </script>