Skip to content

Commit

Permalink
perf: "load more" and "increase page length" (#25081)
Browse files Browse the repository at this point in the history
* refactor: saparate click handlers for "load more" and "change page length"

* perf: "load more" or "increase page length"

Only request the required additional data, not all data.
  • Loading branch information
barredterra committed Feb 29, 2024
1 parent 0fff275 commit 81785ae
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions frappe/public/js/frappe/list/base_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ frappe.views.BaseList = class BaseList {

this.start = 0;
this.page_length = frappe.is_large_screen() ? 100 : 20;
this.selected_page_count = this.page_length;
this.data = [];
this.method = "frappe.desk.reportview.get";

Expand Down Expand Up @@ -395,20 +396,32 @@ frappe.views.BaseList = class BaseList {

this.$paging_area.on("click", ".btn-paging", (e) => {
const $this = $(e.currentTarget);

// set active button
// Set the active button
// This is always necessary because the current page length might
// have resulted from a previous "load more".
this.$paging_area.find(".btn-paging").removeClass("btn-info");
$this.addClass("btn-info");

this.start = 0;
this.page_length = this.selected_page_count = $this.data().value;
const old_page_length = this.page_length;
const new_page_length = $this.data().value;

this.refresh();
this.selected_page_count = new_page_length;
if (this.page_length > new_page_length) {
this.start = 0;
this.page_length = new_page_length;
} else {
this.start = this.page_length;
this.page_length = new_page_length - this.page_length;
}

if (old_page_length !== new_page_length) {
this.refresh();
}
});

this.$paging_area.on("click", ".btn-more", (e) => {
this.start += this.page_length;
this.page_length = this.selected_page_count || 20;
this.start = this.data.length;
this.page_length = this.selected_page_count;
this.refresh();
});
}
Expand Down

0 comments on commit 81785ae

Please sign in to comment.