DEV Community


Posted on • Updated on

Use a composable function to customize the table footer of vue3-easy-data-table

Before you start this tutorial, please make sure you have known how to use vue3-easy-data-table, you can check here for the document.

First of all, we need to install and import use-vue3-easy-data-table which provides customization related composable functions.

npm install use-vue3-easy-data-table
Enter fullscreen mode Exit fullscreen mode


Image description

Script part:

<script lang="ts" setup>
import type { Header, Item } from "vue3-easy-data-table";
import { computed, ref } from "vue";
import { mockClientItems } from "../mock";
import { usePagination } from "use-vue3-easy-data-table";
import type { UsePaginationReturn } from "use-vue3-easy-data-table";

const dataTable = ref();

const {
}: UsePaginationReturn = usePagination(dataTable);

const headers: Header[] = [
  { text: "Name", value: "name" },
  { text: "Address", value: "address" },
  { text: "Height", value: "height", sortable: true },
  { text: "Weight", value: "weight", sortable: true },
  { text: "Age", value: "age", sortable: true },
  { text: "Favourite sport", value: "favouriteSport" },
  { text: "Favourite fruits", value: "favouriteFruits" },

const items: Item[] = mockClientItems(200);
Enter fullscreen mode Exit fullscreen mode

We can see from the above that firstly we use a variable called dataTable to obtain the reference of table DOM elements. Then we use dataTable as a parameter of the usePagination which is a composable function returns table footer related variables and functions:

Image description

The variables usePagination returns are all reactive, for example, if you call the nextPage function, then the currentPageFirstIndex, currentPageLastIndex and currentPaginationNumber variables will update, so finally you can use these variables in template and write style code to customize your own table footer:

Template part:


  <div class="customize-footer">
    <div class="customize-index">
      Now displaying: {{currentPageFirstIndex}} ~ {{currentPageLastIndex}} of {{clientItemsLength}}

    <div class="customize-buttons">
        v-for="paginationNumber in maxPaginationNumber"
        :class="{'active': paginationNumber === currentPaginationNumber}"

    <div class="customize-pagination">
      <button class="prev-page" @click="prevPage" :disabled="isFirstPage">prev page</button>
      <button class="next-page" @click="nextPage" :disabled="isLastPage">next page</button>
Enter fullscreen mode Exit fullscreen mode

Style part

<style scoped>
.customize-footer {
  margin: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
.customize-footer div {
  margin: 5px;
.customize-button {
  display: inline-block;
  width: 20px;
  height: 20px;
  text-align: center;
  border-radius: 100%;
  cursor: pointer;
  padding: 3px;
  line-height: 20px;
} {
  color: #fff;
  background-color: #3db07f;
.customize-pagination button {
  margin: 0 5px;
  cursor: pointer;

Enter fullscreen mode Exit fullscreen mode

If you are interested about vue3-easy-data-table, please check the document here:

And very thankful if you can give me a Github ⭐ for supporting me, repository link:

Top comments (0)