In vue, pagination links are displayed as dots instead of numbers

Struggling to integrate pagination in vue. Facing an issue where the pagination links are appearing as dots, depicted in the attached image. The correct number of pagination links display and I can navigate through different pages using the side navigation arrows on the pagination links (<,>). Uncertain about what's causing this error. Assistance in resolving this problem is greatly appreciated.

https://i.stack.imgur.com/3WqOa.png

<template>
  <v-app class="abilities">
    <v-data-table
      :headers="headers"
      :items="users"
      hide-actions
      class="user-table"
      v-bind:pagination.sync="pagination"
    >
      <template slot="items" slot-scope="props">
        <td>{{ props.item.date }}</td>
        <td>{{ props.item.description }}</td>
      </template>
      <template slot="no-data" >
        <v-alert id='no-data' :value="true" color="error" icon="warning">
          No User Yet
        </v-alert>
      </template>
    </v-data-table>
    <v-layout row wrap v-if="this.users.length > 5">
      <v-flex xs12>
        <div class="user-pagination">
          <v-pagination v-model="pagination.page" :length="pages"></v-pagination>
        </div>
      </v-flex>
    </v-layout>
  </v-app>
</template>


<script>
export default {
  data: function() {
    return {
      pagination: {
        rowsPerPage: 5,
        page: 1
      },
      headers: [
        {
          text: 'Date',
          sortable: false,
          value: 'name'
        },
        {
          text: 'Description',
          sortable: false,
          value: 'name'
        },
      ],
      users: [],
    };
  },
  created: function() {
    var that = this;

    this.fetchUsers();
  },
    computed: {
    pages () {
      return this.pagination.rowsPerPage ? Math.ceil(this.users.length / this.pagination.rowsPerPage) : 0
    }
  },
  methods: {
    fetchUsers() {
      var url = '/users.json?';
      this.$axios
        .get(url)
        .then(response => {
          let data = response.data;
          let users = [];
          data.map((user, index) => {
            let expandedData = user;

            users.push(expandedData)
          });

          this.users = users;
        });
    }
  }
};
</script>

Answer №1

An issue arises with the computed property because it produces Infinity and NaN under certain circumstances:

For instance, when this.pagination.rowsPerPage is 0, the calculation becomes:

return Math.ceil(this.users.length / 0)

resulting in infinity.

Similarly, if this.users.length is 0, the calculation changes to:

return Math.ceil(0 / 0)

yielding NaN.

To resolve this, consider the following adjustment:

computed: {
  pages () {
    return this.pagination.rowsPerPage && this.users.lenght!= 0 ? Math.ceil(this.users.length / this.pagination.rowsPerPage) : 0
  }
},

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Referencing a variable within a string: Discord.js Hyperlink

Essentially, when attempting to use a discord hyperlink, I found that breaking the string to add a variable does not work as expected. I have tried calling it using $ and {} but it still doesn't work. .addField('Shortcuts', $'[Profil ...

Is it possible for jquery JSON AJAX to block all users?

On my website, I use AJAX to load an RSS feed on the client side when the page loads. If a user repeatedly presses F5, could the owner of the RSS feed ban my entire website instead of just that one user? This would prevent others from loading the RSS feed ...

A guide on extracting data from various HTML elements effectively with JavaScript

I'm searching for a universal technique to extract values from multiple HTML elements. For instance: <div>Experiment</div> <select><option>Experiment</option></select> <input value="Experiment" /> These thr ...

Accurate representation of a JavaScript object using Node.js Express

I have a certain structure that I need to display on my JADE page, so I created a JSON-like object to store the data. This is how the JSON object looks like : var dataSet1 = { meta: { "name": "Some text", "minimum": mini_2, "ma ...

Place the item at the top of the list before scrolling downwards

I'm struggling with what seems like it should be a simple task. My goal is to add new items to the top of a list and have the list scroll down to show the new item. So far, I've managed to create and add a new list item using this code snippet: ...

The data from the method in the Vue.js component is not displaying as expected

Currently diving into Vue.JS (2) and exploring the world of components. My current challenge involves using a component within another component, grabbing data from a data method. Here's what I have so far: HTML <div id="root"> <h1> ...

Can Ansible and Pulumi be integrated to work together effectively?

Is it possible to create multiple DigitalOcean droplets in a loop and then use Ansible to configure software and security measures on them, similar to how Terraform works? If so, what would the JavaScript/TypeScript code for this look like? I couldn' ...

Build a row within an HTML table that is devoid of both an ID and a class

Creating an additional row in an HTML table is a common task, but it can become tricky when dealing with multiple forms and tables on one page. In my case, I have a form that contains only a table element, and I want to move some columns from the first row ...

d3.json is unable to parse a value of 'Infinity

My goal is to retrieve data from an SQLite database and convert it into JSON format for use with d3.js in order to create a graph. I have successfully obtained this data in JSON format using the following URL: http://localhost:8085/SQLQuery/?date1=2019-03 ...

"Discover the step-by-step method for retrieving a list of products within a specific category using Vue

I am facing an issue with displaying products based on a specific categoryID. How can I ensure that only the products under each categoryID are displayed? Below is the data for my category ID: { "success": true, "category": { ...

Ways to store firebase configuration parameters as environment variables within a Vue.js application running on firebase hosting

Just diving into the world of Firebase. I recently integrated it into my Vue.js project and now I'm looking for the best way to store the Firebase config parameters in environment variables. Any suggestions on how to do this effectively? ...

How can I detect if the browser's built-in object is available in Angular?

Exploring the Wechat JS API: The Wechat JS API relies on the WeixinJSBridge object within the Wechat built-in browser. This object is not immediately available upon opening the WebView; the client-side needs to initialize it. Once the WeixinJSBridge object ...

The Radiobutton .val() function will always return a value, even if no radiobuttons have been selected

Within my form, I have 3 sets of radio buttons that are all properly labeled. When the user submits the form, I want to verify if they selected an option from each group. To achieve this, I have implemented the following method: $('.form').sub ...

VueJS - Input Image Display Issue Causing Browser Slowdown

I'm experiencing some issues with my VueJS component that includes a file input and displays an image afterwards. Strangely, this is causing my web browsers (both Firefox and Chromium) to freeze up and use massive amounts of CPU. I tried switching to ...

Modify the property of an element within an array

I have an array of objects with a certain property. I need to perform some mathematical operations on this property and return a new array. However, my current approach does not seem to be working as expected. array.map(el => { el.count * 2; r ...

Using JavaScript to assign function arguments based on arbitrary object values

I am facing a challenge with a collection of arbitrary functions and a method that takes a function name along with an object or array of parameters to call the respective function. The issue arises from the varying number of inputs in these functions, som ...

Getting the values of $scope variables from AngularJS in the controller to the view

I have a simple scope variable on my AngularJS Controller. It is assigned a specific endpoint value like this: $scope.isItAvailable = endpoint.IS_IT_AVAILABLE; How can I properly use it in my view (HTML) to conditionally show or hide an element using ng- ...

Unable to activate the 'Click' function in Angular/Typescript after selecting element with 'document.querySelector'

In my Angular 8 Project, there is an element on a page with a unique string attached to the attribute 'data-convo-id'. This element has a click function that loads data based on the data attribute specified above. However, without direct access ...

Combining Bootstrap Vue: utilizing class names alongside HTML tags

(Bootstrap-Vue 2.0, Vue.js 2.5) Is it possible to combine traditional CSS Bootstrap 4 classes with Bootstrap-Vue? For example, can I use the following code snippet: <section id="introduction"> <b-container class="h-100"> & ...

Issues with implementing KendoUI's datepicker in conjunction with Angular

My index.html file contains the following imports: <script src="content/js/angular.js"></script> <link href="content/js/kendo.common-material.min.css" rel="stylesheet" /> <link href="content/js/kendo.material.min.css" rel="styleshe ...