Tips for implementing Bootstrap pagination in VueJS 2

Here is how my website appears:

Jobs.vue:

        <div
          id="jobs"
          class="job-item"
          v-for="(item, index) in showJobs"
          :key="index"
        >
          <router-link
            tag="a"
            :to="{ name: 'Detail', params: { id: item.id } }"
          >
            <h3 class="mleft-27">{{ item.position }}</h3>
          </router-link>
          <div class="job-info flex-wrap">
              <div>                
                <b>{{ item.exprerience }}</b>
              </div>
              <div>
                <b>{{ item.salary }}</b>
              </div>
              <div>                
                <b>{{ item.headequarters }}</b>              
            </div>                   
          </div>
          <div class="info-job flex-wrap">
            <div class="list-info-job" v-html="item.content"></div>
            <router-link
              :to="{ name: 'Detail', params: { id: item.id } }"
            >
              <button class="btn-detail">See Detail</button>
            </router-link>
          </div>
        </div>
        <div class="job-page">
          <b-pagination
            v-model="currentPage"
            :total-rows="rows"
            :per-page="perPage"
            aria-controls="jobs"
        ></b-pagination>

The code above was created following the documentation provided by Vue-Bootstrap. Additionally, my page incorporates filters and a search box, which required utilizing 2 arrays of data. Could this be causing any issues? Please review the updated script below and provide me with a solution.

<script>
import "../assets/job.css";
import axios from "axios";
export default {
  name: "jobs",
  data() {
    return {
      currentPage: 1,
      perPage: 2,
      search: "",
      noData: [],
      display: {
        group_filter: "",
        btn_show_filter: "",
        btn_close_filter: "",
      },
      checks: ["All", "Developer", "Tester", "Designer", "Support"],
      jobinfos: [],
      showJobs: [],
      selected: "All",
    };
  },
  computed: {
     jobs() {
      return this.showJobs.slice((this.currentPage - 1) * this.perPage, (this.currentPage * this.perPage));
    },
    rows() {
      return this.showJobs.length;
    },
  },
  mounted() {
    this.getJobs();
    var self = this;
    window.addEventListener("keyup", function (event) {
      if (event.keyCode === 13) {
        self.searchJob();
      }
    });
  },
  methods: {
    async getJobs() {
      await axios
        .get(`http://localhost:1337/jobinfos`)
        .then((response) => {
          this.jobinfos = response.data;
          this.showJobs = response.data;
        })
        .catch((e) => {});
    },

    searchJob() {
      if (this.selected == "All") {
        this.showJobs = this.jobinfos;
      }
      if (this.selected != "All") {
        this.showJobs = this.jobinfos.filter((i) => i.genres === this.selected);
      }
      if (this.search.length > 1) {
        let searchedJobs = this.showJobs.filter((job) =>
          job.position.toLowerCase().includes(this.search.toLowerCase())
        );
        this.showJobs = searchedJobs;
      }
    },
    selectFilter(item) {
      this.selected = item;
      if (this.selected == "All") {
        this.showJobs = this.jobinfos;
      } else {
        this.showJobs = this.jobinfos.filter((i) => i.genres === this.selected);
      }
    },
  },
};
</script>

I am new to implementing pagination in VueJS, so any assistance would be greatly appreciated. Thank you for your support!

Answer №1

The functionality of the b-pagination module is straightforward - it takes the total number of records (rows) and determines how many records should be displayed per page (perPage). It then generates a set of pages accordingly. The currentPage variable indicates the current page and which records to display, but it's your responsibility to instruct the parent component on what content to render. One suggestion could be using the .slice() method. This method extracts a section of an array based on specified values derived from the currentPage and perPage variables. I've provided a code snippet below to illustrate this—please note that without your CSS, the appearance may differ slightly, but you should still be able to see its functionality.

<new-component>
  <child-component :current-page="1" :per-page="2">
    <job-item position="position1" experience="experience1" salary="salary1" headquarters="headquarters1" />
    <job-item position="position2" experience="experience2" salary="salary2" headquarters="headquarters2" />
    <job-item position="position3" experience="experience3" salary="salary3" headquarters="headquarters3" />
    <job-item position="position4" experience="experience4" salary="salary4" headquarters="headquarters4" />
  </child-component>
</new-component>

This hypothetical Vue component structure represents a job listing feature with pagination. Each "job-item" displays information for a specific position and related details. The "currentPage" and "perPage" props control the visible items according to the current page number. You can customize the styling by incorporating relevant CSS resources.

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

Is it appropriate to use a component inside an entry component?

I'm currently working on a component that triggers a function to open a window: @Component({ selector: 'app-deposits', templateUrl: './deposits.component.html', styleUrls: ['./deposits.component.scss&apo ...

Modifying the values of Highcharts-Vue chart options does not result in any changes once they have been

I recently started incorporating Highcharts into my Vue project using the highcharts-vue library. A) Initially, in pure JavaScript, the following code snippet functions as expected: let b = 5; let data = { a: b } console.log('data', data.a) ...

What is the best way to manage a download link that necessitates an Authorization token when using Angular?

I'm currently working with a REST API in combination with Angular. The issue I'm facing is related to post objects that include file attachments. Every time a user wants to download a file attachment, they must make a call to /get/file/{id}, but ...

A guide on incorporating a method using ES6 Rest into a JavaScript object

My goal is to enhance my Person constructor by adding a method that allows users to add friends. I wanted to utilize the "rest" feature of ES6 to pass a variable number of friends, but I seem to be stuck. My initial attempt resulted in an error ("Uncaught ...

Different ways to determine if a given string exists within an Object

I have an object called menu which is of the type IMenu. let menu: IMenu[] = [ {restaurant : "KFC", dish:[{name: "burger", price: "1$"}, {name: "french fries", price: "2$"}, {name: "hot dog", d ...

New project was successfully generated, but the information is missing when transmitted from React to Django API

I recently developed a React + Django application and implemented a basic CRUD feature. Everything was working smoothly until I encountered an issue while creating a project and storing it in the Django database. When I view the project at projects/list, o ...

ReactJS with conditional closing tags

Here is a sample json response : {id: 1, name: a} {id: 2, name: b} {id: 3, name: c} {id: 4, name: d} {id: 5, name: e} {id: 6, name: f} I am looking to organize these by pairs in my React component like so : <div className="group-item"> ...

VueJS integration with Ag-Grid

I am currently working on integrating Ag-Grid with VueJS in a vanilla JavaScript version, without utilizing any packages or module managers. My attempt involved using the umd version of ag-grid (https://cdn.jsdelivr.net/npm/[email protected] /dist/ag ...

Personalized Map Designs for the Store Finder Plugin on WordPress

I am attempting to customize the appearance of a Google Map using the Store Locator Plus plugin for WordPress. I came across a support thread where someone successfully applied custom styles to the map with the following code snippet: <script> $(win ...

Bidirectional binding with complex objects

In my Angular2 app, I have a class called MyClass with the following structure: export class MyClass { name: Object; } The name object is used to load the current language dynamically. Currently, for two-way binding, I am initializing it like this: it ...

The issue of Storybook webpack failing to load SCSS files persists

I'm running into an issue where my styles are not loading in Storybook, even though I'm not getting any errors. Can someone help me out? My setup involves webpack 2.2.1. I've scoured Stack Overflow and GitHub for solutions, but nothing seem ...

Incorporating the JQuery plugin Lightbox_me into a Ruby on Rails application

Greetings! I am currently attempting to incorporate a popup window using the Lightbox_me plugin in my Ruby On Rails application. After downloading jquery.lightbox_me.js and placing it in the app/assets/javascripts directory, I added //= require jquery.lig ...

The filter functionality isn't functioning properly when attempting to filter an array of objects within a Vuex action

I have a collection of objects that is accessed through a getter. I am using this getter inside an action to filter the items, but no matter what I do, the filtering does not seem to work and it ends up returning all the mapped item IDs. filterItems({ gett ...

ExpressJS exhibits unique behavior based on whether the API is requested with or without the specified PORT number

I have encountered an issue with my 2 flutter web apps. One of them is functioning flawlessly when I request the URL, but the other one only works when I include the port xxxxx:4000/nexus-vote. However, when I remove the port, I receive a status code of 20 ...

When using REACT to fetch data from an API, the absence of an 'Access-Control-Allow-Origin' header may result in access issues

I am working on a project that involves retrieving products from a company's API. After reaching out to the company, they provided me with the following information: CORS allowed origins for local development is "http://localhost:1229" To adhere t ...

How can I showcase the index of `<tr>` and `<td>` elements in a dynamically generated table

How can I print the index of table rows and data on click in javascript? <html> <head> <title>Table Creation</title> <script language="javascript" type="text/javascript"> function createTable() { ...

Instructions for activating and deactivating a numerical input field with a checkbox

Is there a way to create a pair of a checkbox and number field that are linked together? When the checkbox is clicked, it should disable the associated number field. Javascript File: $(document).ready(function(){ $("input[name=check]").click(function(){ ...

How can I allow users to select multiple files with just one input?

Currently, I am able to retrieve a single file from a single input using the following code: $scope.$on("fileSelected", function (event, args) { $scope.$apply(function () { $scope.files.push(args.file); ...

Include a sharing option within the magiczoomplus feature

My current project involves creating a WordPress site using Artisteer along with several plugins to showcase photo galleries. To enhance the user experience, I purchased an e-commerce WordPress theme which features a share button that I really like. Now, I ...

Encountered an issue with setting the property of "something" to undefined when attempting to generate an array sorted by dates

After seeking help from @Kato on Stack Overflow regarding sorting a Firebase AngularFire array into weeks and days, I encountered an error where I cannot set a property of "something" that is undefined. To provide more context, I created a detailed Plunke ...