Looping occurs when performing a custom sort within the <v-data-table> component

I am facing an issue with my table where I am using a custom sort function, but it seems to be getting stuck in a loop.

<v-card>
      <v-toolbar flat>
        <v-toolbar-title>{{ $t('locations.list.title') }}</v-toolbar-title>
        <v-divider class="mx-4" inset vertical></v-divider>
        <div>
          <v-text-field
            append-icon="fa fa-search"
            v-model="params.query"
            :label="$t('locations.labels.search')"
            :disabled="isLoading"
            single-line
            hide-details
            v-debounce:1500="search"
          ></v-text-field>
        </div>
        <v-spacer></v-spacer>
        <v-btn color="primary" :to="{ name: 'locations:create' }">
          {{ $t('locations.labels.add') }}
          <v-icon right>fa fa-plus</v-icon>
        </v-btn>
      </v-toolbar>
      <v-data-table
        :headers="headers"
        :items="locations"
        :page.sync="pagination.current_page"
        :items-per-page="pagination.per_page"
        :loading="isLoading"
        hide-default-footer
        :multi-sort="true"
        :custom-sort="customSort"
        @page-count="pageCount = $event"
      >
        <template v-slot:item.actions="{ item }">
          <v-btn icon :to="{ name: 'locations:edit', params: { id: item.id } }">
            <v-icon>fa fa-edit</v-icon>
          </v-btn>
          <v-btn icon @click="requestDeleteConfirmation(item)">
            <v-icon>fa fa-trash</v-icon>
          </v-btn>
        </template>
      </v-data-table>
      <v-pagination
        v-model="pagination.current_page"
        :length="pagination.last_page"
        @input="search"
      ></v-pagination>
    </v-card>

Below is the method I am using for sorting:

customSort(items, index, isDesc) {
    if (index[0]) {
        const $sort = index
            .reduce((carry, item, index) => {
                const name = item;
                const order = isDesc[index] ? 'ASC' : 'DESC';
                const sort = `${name}:${order}`;
                carry.push(sort);
                return carry;
            }, [])
            .join(',');
        this.params = { ...this.params, $sort };
        console.log('[carry]', $sort);
        this.search();
    } else {
        this.$delete(this.params, '$sort');
    }
    return items;
},

Answer №1

I have a hunch that there might be a cyclic issue occurring where the customSort() function is calling search(), and then search() is calling customSort().

If not, my next thought is that the problem could be related to the v-data-table component. Can you provide more details about this specific component? Is it part of a library or was it custom-made?

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

Adjust a variable based on the current value in JavaScript

I'm looking to change the label based on the value of a textbox. I attempted the code below, but it didn't work as expected. I suspect that the issue lies in not having any value in my textbox. If anyone has a solution for achieving this, please ...

Stop unauthorized changes to URLs using Vue router navigation guards

I have implemented a Vue.js navigation guard to validate users before allowing them to enter a page. If a user fails to meet the specified criteria, the auth guard currently returns false, which is the desired behavior. However, upon doing so, the browser ...

AngularJS: Index not refreshing after deletion of array item(s) using their indexes

I am attempting to eliminate a specific item from an array variable within AngularJS's scope by using the item's index. If you believe this question is a duplicate, please check out the footnote links for related questions that were not exactly ...

Modifying canvas border colors using AngularJS

Currently, I am in the process of learning AngularJS and have developed a website that includes a canvas element. My main objective is to change the border color after clicking on a checkbox. Here is the code snippet for canvas.html : <!DOCTYPE html&g ...

Utilizing asynchronous calls within a forEach loop for executing Firebase operations

My dilemma lies in the inability to successfully implement this code using Firestore (although I'm not entirely sure if this is relevant). The specific code snippet is as follows: prestamoItems() { var myarray = []; var myobject = {}; ...

What is the process for triggering a PHP function when a form element is clicked in a webpage?

Currently, I am trying to implement a jQuery colorbox on my webpage which appears over a <select> drop-down list. My goal is to trigger an AJAX call every time a new option is selected from the drop-down. Even though I have written the following cod ...

Verify a single-time event using jQuery

This is the function I have. If it's confirmed the second time, I won't want to ask again! jQuery('input[type="radio"]').click(function() { if(rel == max || rel < max) { sec(jQuery(this).attr('rel&a ...

My component is not executing the onClick function as expected

I am facing an issue with a component that I imported into another component. Despite clicking on the component, the onclick function does not execute. Here is the code snippet for the component: const HomeFeedCard = ({ name, image, published, quantity, w ...

Issue with parsing an empty array in a Discord bot built with Node.js

Within this API, there exists an empty array marked with a red underline. Sometimes it's void of content, but other times it contains data. My goal is to display Item Spells: there are no effects on this item. when the array is empty. However, instead ...

Contrasts between the storage of data in a static function versus a static object

Trying to figure out the best way to reset a react class component back to its initial state, I came across two different implementations. In my own version, I created an object with initial values and set the component's state equal to it: // My imp ...

How can I retrieve the rating value in AngularJS Bootstrap after submitting a form?

I successfully incorporated the bootstrap star rating feature in an angularjs project. Although everything is functioning properly, I am encountering an issue with retrieving the final rating value after submitting the form. Below is the code snippet: // ...

What is the best way to locate a specific item within an array of objects, especially when each object has the potential to contain an array of objects of the

I am grappling with the challenge of finding a specific object within an array of objects, where the desired object may be nested within another array of one of the objects. I have experimented with various iterations of forEach loops and recursion method ...

What could be causing my Javascript clock to malfunction?

I am having an issue with my clock code, which is supposed to display the date and time set 2 weeks in advance. Unfortunately, it is not working on either local or server environments. Can anyone help me troubleshoot this problem? Here is the code that I ...

What is the process for combining two different animations into one seamless sequence?

After receiving helpful advice from Beetroot, I am attempting to animate multiple images across a gameboard using the .animate() feature with a callback function. However, I am facing an issue where each animation accelerates up to a certain speed, deceler ...

VueJS offers a mixin that is accessible worldwide

I'm looking to create a global mixin that is accessible everywhere, but not automatically inserted into every component. I don't want to use Vue.mixin({...}); Following the guidelines from this source, I have structured my project accordingly. Y ...

Is it possible for you to unveil a concealed window?

Is there a way to load one or more URLs in a hidden window without redirecting the parent page using JavaScript? I would like to avoid browser pop-up blockers by loading the URL in a hidden window and retrieve some data from it. Additionally, I want the ...

Adding a fresh object (key-value pair) to an array in javascript: what you need to know!

My current array is set as : items=[{'id':1},{'id':2},{'id':3},{'id':4}]; Can you advise me on how to include a new pair {'id':5} in the existing array? ...

Double submission issue with Angular form (multiple ajax requests)

My controller seems to be causing a form submission issue in AngularJS where the form is being submitted twice via a get request. Upon checking my database and the console network tab, I noticed that two submissions are logged, with the first submission sh ...

Ways to remove loading spinner from HTML5 video player?

Issue arises on a slow 3G connection as the spinner continues to display even after the video has loaded and started playing. Solution: <video src="d3cvwyf9ksu0h5.cloudfront.net/answer-1530971608.mp4" preload="auto" autoplay control ...

Best practices for integrating JavaScript with PHP and MySQL

When it comes to inserting data into a MySQL database from JavaScript, I typically use AJAX with jQuery's $.POST function and PHP's mysqli function. This allows me to send the data to a PHP script which then inserts it into the database. Here is ...