Vue performance issues with select all checkbox

My webpage contains a list of objects, each with its own checkbox for selection. There is also a 'Select all' checkbox at the top to select all objects at once:

[ ] Select all

[ ] Object 1
[ ] Object 2
[ ] Object 3

The problem arises when I have around 100 objects and click on "Select all," causing the webpage to freeze for a few seconds. Even after removing the search bar meant to filter objects, the performance remains sluggish. Each object has a property called selected to track its selection status. Here are excerpts from my code:

HTML:

<checkbox-input
  id="documentSelectAll"
  :model-value="operatingRows.length === 0 ? false : allSelected"
  @update:modelValue="allSelectPressed"  
/>

---

<tr
  v-for="(row, index) in operatingRows"
  :key="index"
>
  <document-table-row
    :row-idx="index"
    :row-data="row"
    :fields="row.fields"
    :hidden-column-indices="hiddenColumnIndices"
    @toggleSelectedOnRow="toggleSelectedOnRow(row.id)" 
  />
</tr>

Computed properties:

operatingRows() {
    const showRow = (r) => {
      // Search logic omitted
    };
    return this.sorted.filter(showRow);  
},
selectedRows() {
      return this.operatingRows.filter((r) => r.selected);
},
numSelected() {
      return this.selectedRows.reduce((prev, cur) => (cur.selected ? prev + 1 : prev), 0);
},
allSelected() {
      return this.numSelected === this.operatingRows.length;
},

Vuex store:

getters: {
    ...storeStateGetters,
    sorted: (state) => state.sorted,
},

---

mutations: {
    ...storeStateMutations,
    SET_ALL_SELECTED_ON_SORTED(state, isSelected) {
      state.sorted.map((r) => {
        const rn = r;
        rn.selected = isSelected;

        return rn;
      });
    },
},

I suspect that the performance issues may be related to having too many computed properties. Despite attempting to remove them one by one, along with their associated code, the sluggishness persists. It seems that it's not tied to any specific piece of code but rather an architectural concern.

Any assistance on this matter would be greatly appreciated.

Answer №1

It turns out that the issue was caused by a mutation. The solution involved moving the mutation code to an action that triggers a mutation to update the state of the sorted array.

selectOnSorted: ({ commit, rootGetters }, isSelected) => {
  const selectedSorted = rootGetters['documents/sorted'].map((doc) => ({
    ...doc,
    selected: isSelected,
  }));
  commit('SET_SORTED', selectedSorted);
},

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

Creating a node.js function that can be used with OracleDB

I'm currently delving into learning nodeJS, but I'm facing a roadblock and can't seem to figure out what's causing the issue. Even the Debugger isn't providing much help. Any assistance or guidance would be greatly appreciated. The ...

Manipulating CSS classes in multiple divs with JQuery toggle and remove

I am working with the following HTML structure: <div class="wrap"> <div class="red" id="ch1">Content</div> ... <div class="green" id="ch..">Content</div> <div class="red" id="ch..">Content</div> &l ...

I am looking to create a password generator that saves all generated options to a file

I am looking to create a custom password generator that writes all generated options to a file. For example, using the numbers "0123456789" and having a password length of 3 characters. However, I am facing an issue with the file writing process where it ...

What action is triggered on an Apple iPhone when a notification is tapped?

Currently, I am working on a React application and testing it on an Apple mobile phone. One issue I encountered is that when I receive an SMS, the number appears as a suggestion above the keyboard. I want to be able to tap on this number and have it automa ...

What is the process ShaderToy uses to load sound files directly into a texture?

I'm attempting to replicate the functionality of shadertoy in passing audio frequency and waveform into a shader using three.js. In this specific example, it appears that IQ is converting audio data into an image which is then utilized as a texture i ...

Assigning the image source to match the image source from a different website using the image ID

Would it be possible to retrieve the URL of an image from a different webpage using its img ID, and then implement it as the image source on your own website? This way, if the image is updated on the original site, it will automatically update on yours as ...

What is preventing these AngularJS applications from functioning simultaneously?

I have a fully functioning AngularJS app that I developed as a standalone "CreateUser" widget. Now, I am working on creating a second widget called "ViewUsers," which will display a table of current users (with the intention of connecting them or keeping t ...

Axios post request in Spring-Boot backend results in an empty RequestBody. While successful in Postman, the issue persists when sending the request through Axios

I am working on a project with a React frontend and a Spring backend. The backend has a REST service that takes SummarizerData as input and returns the same data as output. There is a form with a textarea input field and submit button. When I send a post ...

Why is the render not showing up on the screen when combining Vue 3 with VTK.js?

While going through the specified VTK.js/Vue.js tutorial with a newer 3.x version, why is it that the cone doesn't appear on the browser window? ...

Having trouble implementing connect-busboy in my Node.js application

Currently, I'm trying to implement image uploads in my node.js application using connect-busboy. Here's the code snippet I've written based on the reference guide https://www.npmjs.org/package/connect-busboy: router.post('/upload&apos ...

`Warning: The alert function is not working properly in the console error

I am currently working on integrating otp functionality into my Ionic 3 project. I am facing an issue where I am able to receive the otp, but it is not redirecting to the otp receive page due to a specific error. Below is the console error that I am encou ...

Strikeout list on click of a mouse

Is there a way to apply strikethrough formatting to text with just a mouse click? The CSS for lists is beyond the form field margin. I've tried multiple methods without success. No matter how many times I change the code, I can't seem to get it r ...

Is it possible to dynamically choose between GET and POST methods for an AJAX request?

Consider the following code snippet which intercepts the form submission event from two different forms. $("#aaa, #bbb").submit(function(e) { e.preventDefault(); var form = $(this); var url = form.attr('action'); $.ajax({ ...

Having trouble updating information using axios and vue-python

I encountered a problem while attempting to update an element from my form. Here is the code snippet: <script setup> const updateSupply = async () => { console.log("Test"); errors.value = "" try { ...

Using routes with optional parameters can inhibit the loading of other routes

In my Node.js app based on Express, I have implemented three different routes. app.get('/', function (req, res) { // }) app.get('/findOne', function (req, res) { // }) app.get('/getFour', function (req, res) { // }) Init ...

When a webpage is moved, the globalProperties variable of "vue3 typescript" is initialized to null

main.ts const app = createApp(App) .use(router) .use(createPinia()) .use(vuetify) .use(vue3GoogleLogin, googleLogin) const globalProps = app.config.globalProperties; globalProps.isDebugMode = true; vue-shim declare ...

choose option without clicking submit button

I am looking to POST my values from a select box without using a submit button. I want the values to be automatically submitted when an option is selected. Although I have tried the sample code below, I am not getting the desired output: <form action= ...

Creating a nested function and utilizing the return statement in JavaScript

I am facing an issue with my custom function that contains an ajax call. I need to retrieve a variable from the ajax function within my custom function, but I'm unable to do so. Why is this happening? Possible solution 1: <script> function ...

Exploring the Depths: A Guide to Displaying Nested Databases with Vue.js and Firebase

Here's my first question on this platform because I'm feeling a bit overwhelmed. I've been experimenting with firebase and vue.js, attempting to navigate through my key-value database construct. Below is the JSON data I exported: { "c ...

Configuring RingoJS to search for necessary modules within the node_modules folder

Currently, I am in the process of transitioning a service from nodejs to ringojs. My main hurdle involves the usage of require(). To illustrate, take a look at this snippet: var restify = require('restify'); The issue arises when RingoJS is una ...