xref: /openbmc/webui-vue/src/components/Mixins/BVPaginationMixin.js (revision d36ac8a8be8636ddd0e64ce005d507b21bcdeb00)
1import i18n from '@/i18n';
2export const currentPage = 1;
3export const perPage = 20;
4export const itemsPerPageOptions = [
5  {
6    value: 10,
7    text: '10',
8  },
9  {
10    value: 20,
11    text: '20',
12  },
13  {
14    value: 30,
15    text: '30',
16  },
17  {
18    value: 40,
19    text: '40',
20  },
21  {
22    value: 0,
23    text: i18n.global.t('global.table.viewAll'),
24  },
25];
26const BVPaginationMixin = {
27  watch: {
28    perPage(newPerPage) {
29      // When switching to "View all" (perPage === 0), reset to first page
30      // to avoid empty views when previously on a later page.
31      if (newPerPage === 0) {
32        this.currentPage = 1;
33      }
34    },
35  },
36  methods: {
37    getTotalRowCount(count) {
38      return this.perPage === 0 ? 0 : count;
39    },
40  },
41};
42
43export default BVPaginationMixin;
44