Tips for maintaining optimal pagination functionality post CRUD operations

I have a Vue component that displays all my records and allows me to edit each one. With over 100 records, I am implementing pagination for efficient navigation.

Issue: For instance, when I try to edit a record on page 3 of the pagination, after updating the record, the pagination resets to page 1. This occurs because I fetch the data again post-update.

Question: How can I enhance my code to prevent this reset? Is it necessary to re-fetch the data to reflect the changes?

Vue Component

<template>
<div>
    <h2> Quest template </h2>
    ...
            </form>
        </div>
    </div>
</div>
</template>

Vue Component Script

<script>
export default {
    data() {
        return {
            quests: [],
            quest: {
                id: '',
                name: '',
                price: '',   
            }, 
            quest_id: '',
            pagination: {},
            edit: false
        }
    },
    created() {
        this.fetchQuests();
    },
    methods: {
        fetchQuests(page_url) {
            ...
        },
        makePagination(meta,links) {
           ...
        },
        updateQuest() {
            if(this.edit) {
               ...
            } 
        },
        editQuest(quest) {
           ...
        }
    }
}
</script>

Answer №1

This inquiry seems to lack specificity. If you are the author of this question, it's evident that you possess some level of expertise. In simple terms, why not just refresh the existing page? By storing the current page in a data variable, you can update without starting from scratch and simply reload the present URL.

data: function() {
    current_page_url: '/api/quests
},
methods: {
    fetchQuests: function(page_url) {
        let vm = this;
        page_url = page_url || this.current_page_url;
        this.current_page_url = page_url;
        fetch(page_url, {
            headers : { 
                'Content-Type': 'application/json',
                'Accept': 'application/json'
            }
        })
        .then(res => res.json())
        .then(res => {
            this.quests = res.data;
            vm.makePagination(res.meta, res.links);
        })
        .catch(error => console.log(error));
    }
}

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

``The modification of an input value after it has been initially

I find myself in a perplexing situation where I am setting a value to an input element from a route parameter. <input type="search" class="form-control search-control" :value="search"> Below is the search computed function: computed: { search() ...

What is the best way to save an integer in HTML's localStorage instead of a string?

I've encountered an issue while using the localStorage feature in a game I'm developing. Specifically, the money variable should be increasing by 1 every second. Here's a snippet of my code: var money = 0; window.onload = function () { ...

Issue with Setting Value in JQuery Select Box

I am in the process of designing a webpage that allows users to edit listings they have created on my website. These listings fall under three main categories, each with its own set of subcategories. To streamline this process, I am implementing AJAX to dy ...

A dynamic 3-column layout featuring a fluid design, with the middle div expanding based on the

Sorry for the vague title, I'm struggling to explain my issue clearly, so let me elaborate. I am using flexbox to create a 3-column layout and want the middle column to expand when either or both of the side panels are collapsed. Here is a screenshot ...

arrange list in Angular.js

Currently, I am attempting to sort an array using Angular JS with the orderBy function. However, I am experiencing difficulties sorting it based on a specific key. Below is the code snippet: var app = angular.module('sortModule', []) app.contr ...

Utilize VueI18n to dynamically translate JavaScript variables into different languages

Trying to show a notification based on a server returned value is my current challenge. I am uncertain about how to dynamically retrieve the translation value using the received key's value. For instance, if the error.response.data.errorDetailsCode v ...

Checking if an object is an array in MooTools

Does MooTools have a built-in method for distinguishing between objects and arrays? ...

Utilize Express to deliver dynamically generated or stored images

My latest project is an innovative image delivery application that can serve images and dynamically resize/change their extension as needed. For the routing, I utilized Express and Sharp for processing the images. One challenge I encountered is high CPU ...

The functionality of 'rich-voice-editor' is currently not operational when trying to utilize the npm package known as quill-rich-voice-editor

Currently, I am utilizing an npm package within my Angular project. "quill": "^1.3.6", "quill-rich-voice-editor": "^0.4.0", Upon adding the line 'rich-voice-editor': true, it triggers the error message cor ...

Code syntax error detected (scrollbar)

I am currently working on incorporating a custom content scroller found at this link into my project. I would like to adjust the scroll inertia but seem to have encountered a syntax error in the code snippet below. Could you please help me identify and c ...

How can I retrieve the numeric key code when the 'Shift' key is being held down during a KeyboardEvent?

When working on my application, I encountered the need to identify if the user pressed any number keys (main keyboard or numpad) in combination with the shift/ctrl/alt keys. This is crucial because the key pressed corresponds to a number in the array (ran ...

The loading time for the NextJS production build is unacceptably sluggish

Recently, I started working with NextJS and deployed my project on Netlify as a production build. However, I've noticed that there is a significant delay of around 3-4 seconds when navigating to a specific page using the next router. Surprisingly, thi ...

Leveraging mongo-triggers for automation

I just completed the installation of mongo-triggers by running: npm install mongo-triggers Now, I'm attempting to set up a simple "hello world" example: var MongoClient = require('mongodb').MongoClient; var triggers = require("mongo-trigg ...

Insert a fresh item into the existing unordered list

Every time I enter something in the prompt, it shows up as "undefined". What I actually want is for whatever I type into the prompt to be added as a new list item. For instance, if I type "Food" in the prompt, I expect to see "Food" appear on the second li ...

NUXT: ERROR Unexpected export token encountered while running npm dev command

I am relatively new to using nuxt and currently working on my first website with it. I encountered an error that I am struggling to resolve. My WSL Ubuntu development environment was functioning properly until I mistakenly ran npm run build instead of npm ...

What is the recommended way to include an image in a v-for loop in Vue.js?

I have attempted various online solutions, but I am still unable to display images on the screen. Could it be a simple mistake? The file names and folders are accurate. When providing the path, I aim to retrieve the image associated with the sub-club name ...

Using React, update the checkbox so that it dynamically changes from checked to unchecked

Hey there, I'm currently working on a table that includes checkboxes. The idea is that when I click on "Add Entries", a modal opens up; and when I click on "Done", I want the checkboxes to become unchecked without having to refresh the page. Do you ha ...

Avoiding Scroll Reset on Browser Navigation with Delayed Transition

I've recently implemented a delay in my router configuration on my website. However, I've noticed that when I try to navigate using the browser's back and forward buttons, it first jumps to the top of the page because of the delay set with { ...

Encountering difficulties starting npm after deploying NextJS app on Azure App Service

When attempting to deploy a Next.js app from a mono repo to Azure AppService (Linux), I have encountered partial success. The package is visible in Data/SitePackages, but the startup command (npm start) fails to initiate the application. The configuration ...

Calculating the sum of all values in the database

In my database, I have a value called task_time. I want to add this value to itself so that the total time is calculated as totalTime = task_time + task_time + ... + task_time. This is how I retrieve the data: function getEndTasks() { $http.get(& ...