npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-bootstrap-paginator

v1.0.0

Published

A Vue.js 2 component for simple pagination with Bootstrap layout

Downloads

9

Readme

vue-bootstrap-paginator

A Vue.js 2 component for simple pagination with Bootstrap layout.

npm version

npm i --save vue-bootstrap-paginator

Narrow template

narrow template

Full template

full template

Usage

The component has the following properties:

  • page: current page
  • pages: total number of pages
  • width: maximum number of pages after which compact mode will be used
  • pageFn: a function to generate href attribute for a page, e.g.,
function pageFunction(page) {
    return `./${page}`
}

The component will emit change event with new page number when a user changes the page.

You can require the component in Vue components:

<template>
    <div class="parent-component">
        <pagination :page="page" :pages="totalPages" :width="20" @change="onPageChange" :pageFn="pageFn"></pagination>
    </div>
</template>
<script>
    const Pagination = require('vue-bootstrap-paginator')
    module.exports = {
        data: () => ({
            totalPages: 15,
        }),
        components: { Pagination },
        methods: {
            onPageChange: function (page) {
                console.log('New page: %s', page)
                this.$router.push(this.pageFn(page))
            },
            pageFn: function (page) {
                return `./${page}`
            },
            handleKeyUp: function (event) {
                if (event.keyCode === 39 && this.page < this.totalPages) {
                    this.$router.push(this.pageFn(this.page + 1))
                }
                if (event.keyCode === 37 && this.page > 1) {
                    this.$router.push(this.pageFn(this.page - 1))
                }
            },
        },
        computed: {
            page: function () {
                // when route param changes, change the page
                return Number(this.$route.params.page) || 1
            },
        },
        created: function () {
            window.addEventListener('keyup', this.handleKeyUp)
        },
        beforeDestroy: function () {
            window.removeEventListener('keyup', this.handleKeyUp)
        },
    }
</script>

Or you can register pagination as a global component:

const Vue = require('vue')
const Pagination = require('vue-bootstrap-pagination')
Vue.component('pagination', Pagination)

Generated HTML for full template

<ul class="pagination">
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./4" aria-label="Previous">«</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./1">1</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./2">2</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./3">3</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./4">4</a>
    </li>
    <li data-v-7e3a6e65="" class="active">
        <a data-v-7e3a6e65="" href="./5">5</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./6">6</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./7">7</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./6" aria-label="Next">»</a>
    </li>
</ul>

Generated HTML for narrow template

<ul class="pagination">
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./4" aria-label="Previous">«</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./1">1</a>
    </li>
    <li data-v-7e3a6e65="" class="hellip disabled">
        <span data-v-7e3a6e65="">…</span>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./4">4</a>
    </li>
    <li data-v-7e3a6e65="" class="active">
        <a data-v-7e3a6e65="" href="./5">5</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./6">6</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./7">7</a>
    </li>
    <li data-v-7e3a6e65="" class="">
        <a data-v-7e3a6e65="" href="./6" aria-label="Next">»</a>
    </li>
</ul>

Testing

Tested with Karma, PhantomJS, Jasmine & Jasmine-Jquery

npm t