Giter VIP home page Giter VIP logo

vue-pagination's Introduction

vue-pagination

Vue pagination component for use with Bootstrap and Laravel pagination.

Software License Packagist

To use with Vue.js 1 use the 1x version.

Laravel is not required as long as the pagination object contains the required attributes

  • current_page,
  • last_page,
  • per_page,

Installation

npm install --save vue-bootstrap-pagination

or

yarn add vue-bootstrap-pagination

Example

import pagination from 'vue-bootstrap-pagination'

new Vue({
  el: '#app',
  data() {
    return {
      items: [],
      pagination: {
        total: 0,
        per_page: 12,    // required
        current_page: 1, // required
        last_page: 0,    // required
        from: 1,
        to: 12
      },
      paginationOptions: {
        offset: 4,
        previousText: 'Prev',
        nextText: 'Next',
        alwaysShowPrevNext: true
      }
    }
  },
  methods: {
    loadData() {
      const options = {
        params: {
          paginate: this.pagination.per_page,
          page: this.pagination.current_page,
          /* additional parameters */
        }
      };
      this.$http.get('/getData', options)
        .then(response => {
          this.items = response.data.data;
        
          // Overwrite pagination object
          this.pagination = response.data.pagination; // API response edited to have pagination data under pagination object
        
          // Or overwrite only values
          /*
            this.pagination.current_page = response.data.current_page;
            this.pagination.last_page = response.data.last_page;
            ...
          */
         })
         .catch(error => {
            // handle error
         });
    }
  },
  components: {
    pagination
  }
})
<body id="app">
  <ul class="list-group">
    <li class="list-group-item" v-for="item in items">{{ item.name }}</li>
  </ul>

  <pagination :pagination="pagination" :callback="loadData" :options="paginationOptions"></pagination>
</body>

Props

Name Type Default Required Description
pagination Object true Pagination object used to create pagination
callback Function true Callback function used to load data for selected page
options Object Configuration. Look below for available options
size String Change the default size of the pagination. Options: large, small.

Offset prop has ben removed with version 2.10.0. Use options.offset instead

Options
Name String Default Description
offset Number 3 Left and right offset of pagination numbers to display
ariaPrevious String Previous Change default aria previous text
ariaNext String Next Change default aria next text
previousText String « Change default previous button text
nextText String » Change default next button text
alwaysShowPrevNext Boolean false Show prev/next button even if on first/last page

If you change this.pagination.per_page the callback function will be called

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

vue-pagination's People

Contributors

neoglyph avatar pogachar avatar remo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-pagination's Issues

Does not work "vue-bootstrap-pagination": "^2.10.3"

I'm using your plugin. But he for some reason does not work for me. To check, I made an alert, but it is not called. What is the reason I can not understand

<template>
    <div>
    <ul class="list-group">
        <li class="list-group-item" v-for="item in items">{{ item.name }}</li>
    </ul>

        <no-ssr>
            <pagination :pagination="pagination" :callback="loadData" :options="paginationOptions"></pagination>
        </no-ssr>
    </div>
</template>

<script>
import axios from 'axios'
import $ from 'jquery';
import pagination from 'vue-bootstrap-pagination/dist/vue-bootstrap-pagination.common.js'

export default {
    data() {
        return {
            items: [],
            pagination: {
                total: 0,
                per_page: 12,    // required
                current_page: 1, // required
                last_page: 0,    // required
                from: 1,
                to: 12
            },
            paginationOptions: {
                offset: 4,
                previousText: 'Prev',
                nextText: 'Next',
                alwaysShowPrevNext: true
            }
        }
    },
    methods: {
        loadData() {
            alert(1);
            const options = {
                params: {
                    paginate: this.pagination.per_page,
                    page: this.pagination.current_page,
                    /* additional parameters */
                }
            };
            axios.get('http://core-rest.evgarik.ru/api/brends', options)
                .then(response => {
                    this.items = response.data.data;

                    // Overwrite pagination object
                    this.pagination = response.data.pagination; // API response edited to have pagination data under pagination object

                    // Or overwrite only values
                    /*
                     this.pagination.current_page = response.data.current_page;
                     this.pagination.last_page = response.data.last_page;
                     ...
                     */
                })
                .catch(error => {
                    // handle error
                });
        }
    },
    components: {
        pagination
    }
}
</script>

IE11 JS error under [email protected]

I am seeing this error in IE11 when building my project with webpack (via laravel mix) using the new built 2.10.3 version:

[Vue warn]: Error in render function: "TypeError: Object doesn't support property or method 'assign'"

I believe it is this section of code:

...
    config: function config() {
      return Object.assign({
        offset: 3,
...

See:
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Browser_compatibility

The changes from 2.10.2 to 2.10.3 did fix the previous IE11 error related to template strings: #16 ( 'Invalid character' on the open backtick ` ) for me.

Error on gulp --production with elixir 6

I'm still having this issue, help please!! babel is include since elixir 5, so i don't know what to do in this case

[13:16:42] ldelcampo:molinillos git:(master*) $ gulp --production
[13:19:37] Using gulpfile ~/Sites/molinillos/gulpfile.js
[13:19:37] Starting 'all'...
[13:19:37] Starting 'sass'...
[13:19:37] Finished 'sass' after 306 ms
[13:19:37] Starting 'webpack'...
{ Error
    at new JS_Parse_Error (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1534:18)
    at js_error (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1542:11)
    at parse_error (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1667:9)
    at Object.next_token [as input] (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1946:9)
    at next (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2075:25)
    at expect_token (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2108:20)
    at expect (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2113:36)
    at eval (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2686:13)
    at eval (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2136:24)
    at expr_atom (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2616:35)
  message: '/Users/ldelcampo/Sites/molinillos/app.js: Unexpected character \'`\'',
  fileName: '/Users/ldelcampo/Sites/molinillos/app.js',
  lineNumber: 11365,
  stack: 'Error\n    at new JS_Parse_Error (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1534:18)\n    at js_error (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1542:11)\n    at parse_error (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1667:9)\n    at Object.next_token [as input] (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1946:9)\n    at next (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2075:25)\n    at expect_token (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2108:20)\n    at expect (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2113:36)\n    at eval (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2686:13)\n    at eval (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2136:24)\n    at expr_atom (eval at <anonymous> (/Users/ldelcampo/Sites/molinillos/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2616:35)',
  showStack: false,
  showProperties: true,
  plugin: 'gulp-uglify' }

Problems with gulp production

Always when I'm trying to minify my app, Gulp throw me this error
{ Error at new JS_Parse_Error (eval at <anonymous> (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1534:18) at js_error (eval at <anonymous> (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1542:11) at parse_error (eval at <anonymous> (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1667:9) at Object.next_token [as input] (eval at <anonymous> (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1946:9) at next (eval at <anonymous> (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2075:25) at expect_token (eval at <anonymous> (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2108:20) at expect (eval at <anonymous> (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2113:36) at eval (eval at <anonymous> (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2686:13) at eval (eval at <anonymous> (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2136:24) at expr_atom (eval at <anonymous> (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2616:35) message: '/Users/ldelcampo/Sites/crm/app.js: Unexpected character \''',
fileName: '/Users/ldelcampo/Sites/crm/app.js',
lineNumber: 148,
stack: 'Error\n at new JS_Parse_Error (eval at (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), :1534:18)\n at js_error (eval at (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), :1542:11)\n at parse_error (eval at (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), :1667:9)\n at Object.next_token [as input] (eval at (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), :1946:9)\n at next (eval at (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), :2075:25)\n at expect_token (eval at (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), :2108:20)\n at expect (eval at (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), :2113:36)\n at eval (eval at (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), :2686:13)\n at eval (eval at (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), :2136:24)\n at expr_atom (eval at (/Users/ldelcampo/Sites/crm/node_modules/laravel-elixir/node_modules/uglify-js/tools/node.js:28:1), :2616:35)',
showStack: false,
showProperties: true,
plugin: 'gulp-uglify' }`

but when try without minify the code, everything works properly. Searching on the code is about template literals with the backtick, but is not the only thing that gulp doesn't supports, can you help me?

Unexpected character '`' [./~/vue-bootstrap-pagination/vue-bootstrap-pagination.js:2,0]

I'm having problems again, now with Laravel 5.4 when try to do npm run production. I'm having this:

`[14:27:58] ldelcampo:crm git:(v1.5*) $ npm run production

@ production /Users/ldelcampo/Sites/crm
cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

95% emitting

ERROR Failed to compile with 1 errors 2:28:31 PM

error

/js/app.js from UglifyJs
Unexpected character '`' [./~/vue-bootstrap-pagination/vue-bootstrap-pagination.js:2,0][/js/app.js:32970,14]

                                                                                                Asset      Size  Chunks                    Chunk Names

fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.eot?f4769f9bdb7466be65088239c12046d1 20.1 kB [emitted]
fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.svg?89889688147bd7575d6327160d64e760 109 kB [emitted]
fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.ttf?e18bbf611f2a2e43afc071aa2f4e1512 45.4 kB [emitted]
fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.woff?fa2772327f55d8198301fdb8bcfc8158 23.4 kB [emitted]
fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.woff2?448c34a56d699c29117adc64c43affeb 18 kB [emitted]
/js/app.js 1.24 MB 0 [emitted] [big] /js/app
/css/app.css 119 kB 0 [emitted] /js/app
mix-manifest.json 66 bytes [emitted]

npm ERR! Darwin 16.5.0
npm ERR! argv "/usr/local/Cellar/node/7.9.0/bin/node" "/usr/local/bin/npm" "run" "production"
npm ERR! node v7.9.0
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ production: cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ production script 'cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js'.
`

this is my package.json

{ "private": true, "scripts": { "dev": "npm run development", "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", "watch-poll": "npm run watch -- --watch-poll", "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", "prod": "npm run production", "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" }, "devDependencies": { "axios": "^0.15.3", "babel-preset-latest": "^6.24.1", "bootstrap-sass": "^3.3.7", "cross-env": "^3.2.3", "jquery": "^3.1.1", "laravel-mix": "0.*", "lodash": "^4.17.4", "vue": "^2.2.*" }, "dependencies": { "vue-bootstrap-pagination": "^2.10.2" } }

Change class of rendered pagination

Hi. Thank you for providing this awesome plugin. I just want to ask if there is a way to change the class of the rendered pagination element. I would like to change the class to match my site's design. However, I don't what to change. thanks a lot!

Invalid character

I'm using your package with elixir and everything works fine in all browser EXCEPT IE11 which just leaves me with

SCRIPT1014: Invalid character
File: backend-app.js, Line: 270, Column: 1

Line 270 in the compiled js is

eval("module.exports = {\r\n    template: `<nav>\r\n        <ul class=\"pagination\" v-if=\"pagination.last_page > 0\" :class=\"sizeClass\">\r\n            <li v-if=\"showPrevious()\" :class=\"{ 'disabled' : pagination.current_page <= 1 }\">\r\n                <span v-if=\"pagination.current_page <= 1\">\r\n                    <span aria-hidden=\"true\">{{ config.previousText }}</span>\r\n                </span>\r\n                \r\n                <a href=\"#\" 

.... // snippet
```

So you have any idea what is causing it?

Add page parameter in the url

When I use this lib, how do I add the page parameter in the end of the url when I click the page link, so I can use that url to go to that page directly?

I'm using vue-router

IE 11

In IE 11 I receive:

Invalid character

and my entire js fails.

vue-pagination not working

Hello guys,
i am trying to use this plugin to add pagination to my table.
vue --version : 2.9.6
here is the html code :
<div class="row"> <div class="col-xs-12 col-md-12"> <vuestic-widget :headerText="$t('tables.basic')"> <div class="table-responsive"> <table class="table table-striped first-td-padding" v-for="itemb in items"> <thead> <tr> <td>N</td> <td>H</td> <td>T</td> <td></td> </tr> </thead> <tbody> <tr> <td>{{itemb.n}}</td> <td>{{itemb.h}}</td> <td>{{itemb.t }}</td> <td></td> </tr> </tbody> </table> <pagination :pagination="pagination" :callback="loadData" :options="paginationOptions"></pagination> </div> </vuestic-widget> </div> </div>

and here is the loadData method that is supposed to be called :
methods :{
loadData() {
const options = {
params: {
paginate: this.pagination.per_page,
page: this.pagination.current_page,
/* additional parameters */
}
};
axios.get('/allBlocks', options)
.then(result =>
{
console.log("all blooocks", result.data)
this.items = result.data;
this.pagination.current_page = 1
this.pagination.last_page = 5
}, error => { console.error(error); });
}
},

i don't understand why is it not working , i have followed the instructions stated, but still ... even the log does not show .. it is like the loadData method is not even called.

Thank you,

what is pagination.total use for

the example have pagination.total, but the source code haven't

      pagination: {
        total: 0, // here
        per_page: 12,
        from: 1,
        to: 0,
        current_page: 1
      }

The document outdated

There's no paramter called total but has one last_page as following code.

            if(to >= this.pagination.last_page) {
                to = this.pagination.last_page;
            }

Callback Runs twice on load

I have a weird issue.
When my app loads, two calls are made to the server in quick succession.
I have dug around and found that it behaves correctly (only one fetch) if I just leave the pagination parameters with straightforward integer values:
pagination: { total: 0, per_page: 25, current_page: 1, last_page: 0, from: 1, to: 25 },

The above works.
The moment I change it to the below, then it fetches remote data twice:
pagination: { total: 0, per_page: this.paginate, current_page: 1, last_page: 0, from: 1, to: this.paginate },

//this.paginate is set to 25

In my mounted() function, I call the method responsible for fetching the remote data.
I notice in your example that you don't manually call this, the plugin takes care of it somewhat.
However, if I don't make that call, then nothing happens.
It seems it's either fetch twice or not at all for me.
Any ideas?

Pagination links throwing trim error.

Getting TypeError: exp.trim is not a function error when clicking pagination links.

Seems to be related to the line below being called in the changePage function.

this.$set(this.pagination, 'current_page', page);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.