Footer customization

Method 1: Exposed variables and functions

vue3-easy-data-table exposes some footer related variables and functions:

NameTypeDescription
clientItemsLengthvariableTotal amount of items in client-side mode.
Attention: In server-side mode, please use serverItemsLength prop instead!
currentPageFirstIndexvariableFirst index in current page
currentPageLastIndexvariableLast index in current page
currentPaginationNumbervariableCurrent pagination number
maxPaginationNumbervariableMax pagination number
isLastPagevariableIs the last page
isFirstPagevariableIs the first page
nextPagefunctionNavigate to the next pag
prevPagefunctionNavigate to the previous page
updatePagefunctionNavigate to the specified page
rowsPerPageOptionsvariableOptions of rows per page
rowsPerPageActiveOptionvariableActive option of rows per page
updateRowsPerPageActiveOptionfunctionUpdate active option of rows per page

You can access to these variables and functions through template refsopen in new window. Then you can customize your own footer outside of the vue3-easy-data-table as the examples provided:

Examples

In client mode

<template>
  <EasyDataTable
    ref="dataTable"
    :headers="headers"
    :items="items"
    :rows-per-page="10"
    :hide-footer
  />
  
  <div class="customize-footer">
    <div class="customize-rows-per-page">
      <select
        class="select-items"
        @change="updateRowsPerPageSelect"
      >
        <option
          v-for="item in rowsPerPageOptions"
          :key="item"
          :selected="item === rowsPerPageActiveOption"
          :value="item"
        >
          {{ item }} rows per page
        </option>
      </select>
    </div>

    <div class="customize-index">
      Now displaying: {{currentPageFirstIndex}} ~ {{currentPageLastIndex}} of {{clientItemsLength}}
    </div>
  
    <div class="customize-buttons">
      <span
        v-for="paginationNumber in maxPaginationNumber"
        class="customize-button"
        :class="{'active': paginationNumber === currentPaginationNumber}"
        @click="updatePage(paginationNumber)"
      >
        {{paginationNumber}}
      </span>
    </div>
  
    <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>
    </div>
  </div>
</template>

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

// $ref dataTable
const dataTable = ref();

// index related
const currentPageFirstIndex = computed(() => dataTable.value?.currentPageFirstIndex);
const currentPageLastIndex = computed(() => dataTable.value?.currentPageLastIndex);
const clientItemsLength = computed(() => dataTable.value?.clientItemsLength);

// pagination related
const maxPaginationNumber = computed(() => dataTable.value?.maxPaginationNumber);
const currentPaginationNumber = computed(() => dataTable.value?.currentPaginationNumber);

const isFirstPage = computed(() => dataTable.value?.isFirstPage);
const isLastPage = computed(() => dataTable.value?.isLastPage);

const nextPage = () => {
  dataTable.value.nextPage();
};
const prevPage = () => {
  dataTable.value.prevPage();
};
const updatePage = (paginationNumber: number) => {
  dataTable.value.updatePage(paginationNumber);
};

// rows per page related
const rowsPerPageOptions = computed(() => dataTable.value?.rowsPerPageOptions);
const rowsPerPageActiveOption = computed(() => dataTable.value?.rowsPerPageActiveOption);

const updateRowsPerPageSelect = (e: Event) => {
  dataTable.value.updateRowsPerPageActiveOption(Number((e.target as HTMLInputElement).value));
};

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);
</script>

<style>
/* omit */
...
</style>
NameAddressHeightWeightAgeFavourite sportFavourite fruits
name-1address-1111footballapple
name-2address-2222runningorange
name-3address-3333swimmingpeach
name-4address-4444basketballbanana
name-5address-5555footballapple
name-6address-6666runningorange
name-7address-7777swimmingpeach
name-8address-8888basketballbanana
name-9address-9999footballapple
name-10address-10101010runningorange

Attention: don't forget to set hide-footer to to hide the native footer of vue3-easy-data-table

In server-side mode

Click hereopen in new window to check how to use server-side mode

<template>
  <EasyDataTable
    ref="dataTable"
    v-model:server-options="serverOptions"
    :headers="headers"
    :items="items"
    :server-items-length="serverItemsLength"
    hide-footer
    :loading="loading"
  />

  <div class="customize-footer">
    <div class="customize-index">
      <!-- In server-side mode, please use serverItemsLength prop not clientItemsLength variable !!! -->
      Now displaying: {{currentPageFirstIndex}} ~ {{currentPageLastIndex}} of {{serverItemsLength}}
    </div>
    <!-- omit -->
    <!-- ... -->
  </div>
</template>
Rest api example: http://localhost:8080/api?page=1&limit=5&sortBy=age&sortType=desc

NameAddressHeightWeightAgeFavourite sportFavourite fruits

Attention: In server-side mode, please use serverItemsLength prop instead of clientItemsLength.

Method 2: Composable function

You can alos use usePagination function in use-vue3-easy-data-tableopen in new window to achieve the customization more easily.

Install

npm install use-vue3-easy-data-table

Usage

<template>
  <EasyDataTable
    ref="dataTable"
    :headers="headers"
    :items="items"
    :rows-per-page="10"
    hide-footer
  />
  
  <div class="customize-footer">
    <div class="customize-rows-per-page">
      <select
        class="select-items"
        @change="updateRowsPerPageSelect"
      >
        <option
          v-for="item in rowsPerPageOptions"
          :key="item"
          :selected="item === rowsPerPageActiveOption"
          :value="item"
        >
          {{ item }} rows per page
        </option>
      </select>
    </div>

    <div class="customize-index">
      Now displaying: {{currentPageFirstIndex}} ~ {{currentPageLastIndex}} of {{clientItemsLength}}
    </div>
  
    <div class="customize-buttons">
      <span
        v-for="paginationNumber in maxPaginationNumber"
        class="customize-button"
        :class="{'active': paginationNumber === currentPaginationNumber}"
        @click="updatePage(paginationNumber)"
      >
        {{paginationNumber}}
      </span>
    </div>
  
    <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>
    </div>
  </div>
</template>

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

const dataTable = ref();

const {
  currentPageFirstIndex,
  currentPageLastIndex,
  clientItemsLength,
  maxPaginationNumber,
  currentPaginationNumber,
  isFirstPage,
  isLastPage,
  nextPage,
  prevPage,
  updatePage,
}: UsePaginationReturn = usePagination(dataTable);

const {
  rowsPerPageOptions,
  rowsPerPageActiveOption,
  updateRowsPerPageActiveOption,
}: UseRowsPerPageReturn = useRowsPerPage(dataTable);

const updateRowsPerPageSelect = (e: Event) => {
  updateRowsPerPageActiveOption(Number((e.target as HTMLInputElement).value));
};

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);
</script>

<style>
/* omit */
...
</style>
NameAddressHeightWeightAgeFavourite sportFavourite fruits
name-1address-1111footballapple
name-2address-2222runningorange
name-3address-3333swimmingpeach
name-4address-4444basketballbanana
name-5address-5555footballapple
name-6address-6666runningorange
name-7address-7777swimmingpeach
name-8address-8888basketballbanana
name-9address-9999footballapple
name-10address-10101010runningorange

Type declaration

NameTypeDescription
clientItemsLengthComputedRef<number | undefined>Total amount of items in client-side mode.
Attention: In server-side mode, please use serverItemsLength prop instead!
currentPageFirstIndexComputedRef<number | undefined>First index in current page
currentPageLastIndexComputedRef<number | undefined>Last index in current page
currentPaginationNumberComputedRef<number | undefined>Current pagination number
maxPaginationNumberComputedRef<number | undefined>Max pagination number
isLastPageComputedRef<boolean | undefined>Is the last page
isFirstPageComputedRef<boolean | undefined>Is the first page
nextPage() => voidNavigate to the next pag
prevPage() => voidNavigate to the previous page
updatePage(paginationNumber: number) => voidNavigate to the specified page
rowsPerPageOptionsComputedRef<number[] | undefined>Options of rows per page
rowsPerPageActiveOptionComputedRef<number | undefined>Active option of rows per page
updateRowsPerPageActiveOption(option: number) => voidUpdate active option of rows per page