petritr's avatar
Level 15

Add offset to pagination

I have the following

 <pagination :meta_data="meta_data" :offset="5" v-on:next="fetchLogs"></pagination>

How can i add offset to my pagination so i got 5.. 6 7 8 .. 9

Any help with this

0 likes
4 replies
aurawindsurfing's avatar

You might be mixing up things here. Pagination is build into Laravel but it is not build into VueJs as far as I can tell.

It looks like you try to apply a prop to vue js component and therefore you should look at the component code or docs on how to use it.

Hope it helps!

petritr's avatar
Level 15

@aurawindsurfing

i don't mix anything my question was how to make the offset in vue, i use the laravel pagination.

i fond an solutions, thanks for offering help :)

petritr's avatar
Level 15

@aurawindsurfing yes of course

        props: ['meta_data', 'offset'],
        methods: {
            isCurrentPage(page) {
                return this.meta_data.current_page === page;
            },
            changePage(page) {
                this.$emit('next', page);
            }
        },
        computed: {
            pages() {
                let pages = [];
                let from = this.meta_data.current_page - Math.floor(this.offset / 2);
                if (from < 1) {
                    from = 1;
                }
                let to = from + this.offset - 1;
                if (to > this.meta_data.last_page) {
                    to = this.meta_data.last_page;
                }
                while (from <= to) {
                    pages.push(from);
                    from++;
                }
                return pages;
            }
        },

html

            <li class="pagination-item" v-for="page in pages">
                <a class="page-link" :class="isCurrentPage(page) ? 'active' : ''" @click.prevent="changePage(page)">{{ page }}</a>
            </li>

Parent component

            <pagination :offset="10" :meta_data="meta_data" v-on:next="fetchLogs"></pagination>

Please or to participate in this conversation.