Element Framework

Pagination

  • HTML
  • JS
  • CSS
<div id="wrapper">
  <ef-pagination page-size="5" total-items="32"></ef-pagination>
</div>

                  
#wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  margin-right: 100px;
}

ef-pagination is used when content is divided into separate pages to display the page numbers and enable navigation between them. The component should be positioned at the bottom right of the content.

Basic usage

The pagination component requires the mandatory attributes, page-size and total-items. It will use these to calculate the number of total pages.

By default, pagination will set the initial page to the first page but you can change that using the page attribute.

  • HTML
  • JS
  • CSS
<div id="wrapper">
  <ef-pagination page="3" page-size="5" total-items="32"></ef-pagination>
</div>

                  
#wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  margin-right: 100px;
}
<ef-pagination page="3" page-size="5" total-items="32"></ef-pagination>

Disabled

To disable pagination, use the disabled attribute.

  • HTML
  • JS
  • CSS
<div id="wrapper">
  <ef-pagination disabled page-size="5" total-items="32"></ef-pagination>
</div>

                  
#wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  margin-right: 100px;
}
<ef-pagination disabled page-size="5" total-items="32"></ef-pagination>

Responsive width

The page description section will be hidden if the width of the component is less than the break point, defined by the theme. You can override this value using the CSS variable, --responsive-width.

For example, to hide the page description when the width is less than 400px;

  • HTML
  • JS
  • CSS
<div id="wrapper">
  <ef-pagination page-size="5" total-items="32"></ef-pagination>
</div>

                  
#wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  margin-right: 100px;
}

ef-pagination {
  width: 390px;
  ---responsive-width: 400;
}
  ef-pagination {
    ---responsive-width: 400;
  }

Page changed

The pagination component will fire page-changed with the value of the new page in e.detail.value.

  • HTML
  • JS
  • CSS
<div id="wrapper">
  <ef-pagination id="pagination" page-size="5" total-items="32"></ef-pagination>
</div>
<div id="console">
  Page =&#xA0;<span id="text"></span>
</div>
var pagination = document.getElementById('pagination');
pagination.addEventListener('page-changed', function(e) {
  var text = document.getElementById('text');
  text.textContent = e.detail.value;
});
#wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  margin-right: 100px;
}

#console {
  display: flex;
  align-items: center;
  justify-content: center;
}
<ef-pagination id="pagination" page-size="5" total-items="32"></ef-pagination>
<script>
  var pagination = document.getElementById('pagination');
  pagination.addEventListener('page-changed', function (e) { console.log(e.detail.value) });
</script>

API Reference

Attributes

string
page
Set current page
string
page-size
Number of item per page
string
total-items
Total items
boolean
disabled
Set state to disable

Properties

string
page
Set current page
"1"
string
pageSize
Number of item per page
"10"
string
totalItems
Total items
"10"
boolean
disabled
Set state to disable
false

Methods

next()
Go to the next page
previous()
Go to the previous page
first()
Go to the first page
last()
Go to the last page

Events

page-changed
Fired when the `page` property is changed