Sort icon on b-table column not detected when clicked initially

Just starting out with Vue and Vuex here. Currently using Vue 2.0 along with the bootstrap-vue component for server-side rendering to ensure correct sorting and pagination from the API. I've disabled local sorting on the b-table element.

I apologize for the lengthy explanation, but it's necessary. I've developed a component containing a table and passing in props, including an array of Fields from the parent component. Within the child b-table component, I'm specifying one of these fields as clickable by placing it into the #cell slot and incorporating a b-link tag. Below is the code snippet where I'm inserting into the #cell slot within the child component:

            <!-- Edit button (key field called 'action' in fields array) -->
            <template #cell(action)="row">
              <b-link
                size="sm"
                @click="showItemDetail(row.item, row.index, $event.target)"
              >
                <!-- Edit -->
                {{ row.item[keyField] }}
              </b-link>
            </template>

I've used "action" in the #cell() to correspond with the key defined in the fields array being passed down to the child component via props, which will trigger the item detail view when clicked. Here is how the fields array looks like when passed in:

      fields: [
        {
          key: "action",
          label: "Batch Id",
          sortable: true,
          sortBy: "batchId",
        }, ...

Please note that the key "action" matches the #cell(action) in the b-table child component. This setup results in the batch id column displaying as a link, and upon clicking it, showItemDetail function is invoked to display the item details view successfully. The initial sort order remains as displayed in another column on the table.

ISSUE: When I click on the header of the batch id (action column) to sort for the first time, the server correctly responds and the data gets displayed sorted by batch id. However, the sorting indicator does not update, failing to show the ascending arrow. There is no visual indication of the applied sort except for the actual data order. Despite sending the correct sort order and direction to the server, the client side fails to reflect this on the UI.

Subsequently, upon clicking again, it reverts to ascending order (as if it was never sorted by that column before), and the ascending arrow appears highlighted. Clicking once more sorts it in descending order, accurately displaying the downward arrow. Hence, the issue lies only in the first instance of sorting, where the arrow fails to highlight and recognize the applied sort.

https://i.sstatic.net/cA97l.gif

Thank you for taking the time to read through this. It's very likely that I'm approaching this in the wrong manner, and there might be a more efficient way of abstracting the code and implementing row-click functionality to reveal details, especially in the context of server-side rendering. As I find all of this quite overwhelming at the moment, any suggestions would be greatly appreciated. Thank you.

Answer №1

Here's a clever workaround I used to solve the issue at hand, hoping it might be useful for someone else encountering the same problem:

  1. Inserted the v-bind code snippet into b-table:
   @sort-changed="onSortChanged"
  1. Assigned a class property to the "action" field within the fields array (for easier identification using querySelectorAll).

  2. Addition of the following method:

        async onSortChanged(ctx) {
      //Dealing with sorting changes in Action column:
      // Resolving issue where sort indicator fails to display ascending
      // upon initial click on action column sort
      if (this.fixSortFlag) return;
      if (ctx.sortBy === "action") {
        this.fixSortFlag = true;
        try {
          const el = document.querySelectorAll(".colAction");
          const attr = el[0]?.getAttribute("aria-sort");

          if (ctx.sortDesc === false && attr !== "ascending") {
            // Setting up sort indicator upward
            el[0].setAttribute("aria-sort", "ascending");
            // this.sortOrder = false;
          } else if (attr === "ascending") {
            // Setting down sort indicator
            this.sortOrder = true;
            el[0].setAttribute("aria-sort", "descending");
          }
        } finally {
          this.fixSortFlag = false;
        }
      }
    },

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

Enhance the functionality of the custom transaction form in NetSuite by incorporating new actions

I'm currently working on incorporating a new menu option into the "Actions" menu within a custom transaction form in NetSuite. While I can successfully see my selection in the Actions Menu on the form, I'm running into an issue with triggering th ...

Suggestions on how to refactor redundant code in various peer AngularJS controllers for handling $intervals

In my compact single-page application, I have implemented multiple tabs to display operational status information for different applications. Each tab is associated with a controller that creates $interval objects to make AJAX calls to fetch status data fr ...

The autofocus feature does not function properly while utilizing the onMouseDown event

There are two very similar components that control the focus for the input when it is displayed: Check out this example here Or explore this one In the second scenario, I opted for using the onMouseDown event instead of onClick for the button that trigg ...

"Getters appear to be malfunctioning and it seems that the state value remains immutable within the Vuex

After diving into VueX for the first time, I encountered some challenges: Struggling to access state using getters in store.js. While this.$store.state.java works fine, switching to this.$store.getters.semuaJasa results in no display on the browser. Unabl ...

I would like to know the best approach to utilizing a PHP array or JSON response within JavaScript

Let me present my workflow briefly. While I initiate an Ajax call from the index.phtml file, the Ajax response is as follows: Array ( [Data] => Array ( [0] => Array ( [PlayerId] => 20150 ...

Is there a way to dynamically append options to a Bootstrap selectpicker?

I'm attempting to design a dropdown feature that, when activated by clicking on the first list item, displays a new list of related items next to the initial selection. Here's an illustration: https://i.sstatic.net/fMxAj.png My approach involve ...

displaying database information in a textarea using PHP

I'm fairly new to PHP programming and I've encountered an issue with this particular code. My goal is to display data in a text box when the select button within the grid is pressed. However, I seem to be stuck as the data doesn't show up in ...

Unable to generate a file using fs.appendFile in Node.js

For some time now, I've been working on a program that is meant to save logs from a Slack team. I've managed to get most things working, but I've hit a roadblock with using fs.appendFile() successfully. The documentation states that it shoul ...

Looking to add the Ajax response data into a dropdown selection?

Looking to add select options dynamically, but unsure how to retrieve response values. I am able to fetch all the values in the response, but I struggle with appending them correctly in the select option. I believe the syntax is incorrect. success: funct ...

The contents of my script.js file do not align with the code in the mail

I find myself in a bit of a pickle and could really use some assistance. I recently took over for someone and have been struggling to get my form to send via ajax POST. Despite receiving a 200 OK response, the mail.php file I've been using is not send ...

Understanding ReactJs component syntax: Exploring the nuances and distinctions

Currently diving into the world of Reactjs and working on creating a basic component. I'm puzzled about why this particular syntax for a component: import React, { Component } from 'react'; export default class AboutPage extends Component { ...

Having trouble passing a token for authentication in Socket.IO v1.0.x?

I am currently following a tutorial on creating a token-based authentication system, which can be found here. I have implemented the following code: Code in app.html: var socket = io('', { query: "token=i271az2Z0PMjhd6w0rX019g0iS7c2q4R" }); ...

Using jQuery to create a script that will transition random images simultaneously within a div

I am currently working on a JavaScript script that will animate 10 images flying into a div, appearing side by side. The goal is to have each image fly in randomly with a unique transition. At the moment, my script is almost complete as I've successf ...

Tips for resolving the issue of "Warning: validateDOMNesting(...): <div> cannot be a child of <tbody>"

Users list is passed as a prop to the UserItem Component in order to iterate over the user list and display them on a table. The list is being displayed correctly, and there are no divs in the render return, but an error persists: tried many solutions fou ...

What is the meaning of "bootstrapping" as it relates to Angular 2?

I found a question that is similar to mine, but I think my case (with version 2) has enough differences to warrant a new discussion. I'm curious about the specific purpose of calling bootstrap() in an Angular 2 application. Can someone explain it to ...

Tips for retrieving specific data from MongoDB using Node.js

Currently facing an issue working with Node.js, express, and mongodb when it comes to passing data between frontend and backend. Note: The code below represents middleware code for communication between frontend and backend. I have successfully retrieved ...

Using Three.js, generate a series of meshes that combine to create a seamless 90-degree donut shape

I'm on a quest to discover an algorithm that can create the following shape in Three.js. Here is my rough sketch of the expected shape The number of meshes needed to form the 90 degree donut, as well as the thickness and spacing between them, should a ...

Using Angular.JS to iterate over a nested JSON array using ng-repeat

I am currently working on a People service that utilizes $resource. I make a call to this service from a PeopleCtrl using People.query() in order to retrieve a list of users from a json api. The returned data looks like this: [ { "usr_id" : "1" ...

Different ways to dynamically change tailwind colors during execution

Utilizing tailwind v3, it's feasible to customize existing colors by modifying the tailwind.config file. https://tailwindcss.com/docs/customizing-colors module.exports = { theme: { extend: { colors: { gray: { ...

Creating a fantastic Image Gallery in JavaScript

As I work on creating a basic gallery page with html and css, everything seemed to be running smoothly. However, upon testing it in Google Chrome and IE, the onmouseover function is not responding as expected. The idea is for a larger image to display in t ...