DEV Community

Discussion on: Implementing Pagination feature in Vanilla JS

Collapse
 
lexlohr profile image
Alex Lohr

One usability issue here: the active page should always be in the middle of the rendered buttons, if there are enough pages to pad it. Otherwise, well executed, even though I prefer a functional approach that only calculates which buttons with which properties to show depending on the input that is slightly more reusable and agnostic of page content.

Collapse
 
lakbychance profile image
Lakshya Thakur

Hey thanks for the feedback. I didn't quite get the functional approach. Can you elaborate a bit more for my benefit ?

Collapse
 
lexlohr profile image
Alex Lohr

Without providing a fully working example, instead of having a Pagination object, you merely use a pure function (same input always produces same output) to calculate the pagination that should be displayed:

const getPagination = (currentPage, pages, showPages) => {
  const pagination = []; // ...do the calculation
  return pagination;
};
Enter fullscreen mode Exit fullscreen mode