The sorting feature for columns seems to be malfunctioning in Bootstrap 5

I have utilized bootstrap 5 to create a table, but I am facing an issue when trying to sort the first column as there is no change reflected. Below is how my table is structured:

The structure of the table is as follows:

<table class="table" id="reporttable">
    <thead>
      <tr>
      <th data-sortable="true">Event date & time</th>
      <th data-sortable="true">Event level</th>
      <th data-sortable="true">Event potential damage</th>
      <th data-sortable="true">Report no</th>
      <th data-sortable="true">Report type</th>
      <th data-sortable="true">Report status</th>
    </tr>
    </thead>
    <tbody>

      <td><div v-for="(datetime,index) in reportCreatedAt" :key="index" :style="colourChange(index)">
        {{datetime}}</div>
      </td>

      <td><div v-for="(level,index) in reportStateLevel " :key="index" :style="colourChange(index)" >
        {{level}}</div>
      </td>

      <td><div v-for="(plevel,index) in reportSeverity" :key="index" :style="colourChange(index)">
        {{plevel}}</div>
      </td>

      <td><div v-for="(link,index) in reportId" :key="index" :style="colourChange(index)"  >
        <router-link :to="{name: 'HTML Report', query:{id: link,cont:index+1}}" > 
          Report No {{index+1}} 
        </router-link></div>
      </td>

      <td><div v-for="(type,index) in reportType" :key="index" :style="colourChange(index)">
      {{type}}</div>
      </td>

      <td><div v-for="(status,index) in reportStatus" :key="index" :style="colourChange(index)">
        {{status}}</div>
      </td>

  </tbody>

</table>

My requirement is to sort the entire table based on the "Event date/time" column.

Appreciate any suggestions or assistance provided. Thank you!

Answer №1

Sorting tables with Bootstrap 5 is not supported directly. If you are looking for sorting functionality, consider using alternatives such as Datatables which offers more robust features for table sorting.

Answer №2

After some experimentation, I managed to organize the table data exactly how I wanted.

The key was collecting each row of the column into an array of dictionaries like this:

array=[{id:xx,type:xx,status:xx,level:xx...} {id:xx,status:xx,...}]

Next, I utilized the id to sort the array using the following code snippet:

array.sort((a, b) => {
  if (a.id < b.id) {
    return -1;
  }
  if (a.id > b.id) {
    return 1;
  }
  return 0;
})

This method resulted in a well-organized table sorted by Id as shown in this example.

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

Issue with JavaScript Onclick Event Handler

Rephrasing Full JavaScript Code. Javascript <div id="PopUp1" style="display: none; color: #FFFFFF;"></div> <div id="Mask"></div> <script type="text/javascript"> var Content = '<p>Content!!!!!</p><input ty ...

Is there a way to avoid getting a 404 error in Express when using multiple static directories?

I am working on serving files from two different folders to keep my admin and client content separate. The code I have set up initiates the two folders, but when Express looks for a file like example.css, it first checks the /static directory. If it doesn ...

Is your jquery keydown event detector failing to recognize key inputs?

Lately, I've been working on a new project and encountered an issue with a piece of code that used to work perfectly fine in a previous project. The code in question is $(document).keydown(function(keypressed){});, which I used to detect specific key ...

Ajax: The function assigned to the route does not get executed

Pressing a button triggers a confirmation box. If 'ok' is clicked, the div called 'EventData' should display the word 'reached'. The confirmation box appears when the button is clicked, but 'EventData' does not show ...

What is the way to display the final list item when clicking in jQuery?

I am attempting to achieve a specific behavior where clicking on a button will trigger the content below to scroll in such a way that only the last item in the list is visible. I have been using jQuery for this functionality, but unfortunately, it is not ...

Integrating tilt and zoom functionality on a web page based on mouse movements

While browsing through some messages on chat, I came across something interesting: I noticed that as I moved my mouse left or right, the content would tilt in that direction, and when moving up and down, the content would zoom in or out. It was a really c ...

Tips for disabling default browser input validation in React

https://i.stack.imgur.com/834LB.png Is there a way to remove the message "Please fill out this field" while still keeping the "required" attribute intact? I have my own validation system in place, so I need to use the "required" attribute to determine whe ...

Refresh the inner content (Reverberate PHP) when the button is clicked

Currently, I am at the beginner's level of WordPress and PHP. Despite my efforts in researching on stackoverflow, my limited understanding has hindered me from finding a solution to my issue. On my website, I am utilizing WordPress as the CMS. Specif ...

Is the scrolling functionality acting strange while using React Three Fiber?

In my React Three Fiber application, I have the following structure: Website Canvas NativeHTMLContent Canvas Website The issue I'm facing is that after scrolling down the entire canvas, the scrollbar resets to the top and starts scrolling from the t ...

JavaScript Function to Redirect Page After a Delay of X Seconds

I'm trying to implement a redirect to a specific URL after displaying an error message for 5 seconds. Initially, I used JavaScript like this: document.ready(window.setTimeout(location.href = "https://www.google.co.in",5000)); However, the redirectio ...

Getting a URL path in Next.js without relying on the Link component when the basePath is configured

Base Path from the next.js documentation states: For instance, by setting basePath to /docs, /about will automatically transform into /docs/about. export default function HomePage() { return ( <> <Link href="/about"> ...

Purge excess bins that are not in use

I need to delete a large number of inactive bins from the system, but I can't find an option for mass deletion or inline editing using saved searches. Is there another method to accomplish this task since I have hundreds of records to delete? ...

The animation effects of elements within Vue.JS transition-group are experiencing issues when transitioning out

I'm currently working on implementing a custom toast component with animation in Vue.js 2. Below is the CSS I am using for transitions: .toast-enter-active { opacity: 0; transition: all 1s ease-out; } .toast-enter-to { opacity: 1; } .toas ...

React failing to display basic component

As a newcomer to React, I have a question regarding rendering a basic React component. Here is my setup in index.html: <!DOCTYPE html> <html lang="en> <head> <title>React</title> </head> <body> < ...

Displaying Modal from a separate component

CardComponent: export class Card extends Component<Prop, State> { state = { isCancelModalOpen: false, }; marketService = new MarketService(); deleteMarket = () => { this.marketService .deleteMar( ...

How can I adjust a number using a shifter in JavaScript?

Searching for an event handler where I can use a shifter to adjust the value of a number by moving it left or right. Would appreciate any links to documentation on how to achieve this. Many thanks UPDATE Thanks to the suggestions from other users, I hav ...

A marker popup in React with Leaflet closes immediately upon clicking when using leaflet-pixi-overlay

Currently, I am developing a leaflet map using React and PixiOverlay for better performance while drawing markers. However, I have encountered an issue with handling popups while working on the code below: The Marker's click event triggers correctly ...

The virtual slider in SwiperJS is showcasing empty slides when using the renderExternal feature with vueJS

Looking to integrate virtual slides with the swiper element in a vueJS project. However, I'm encountering an issue where the slides are not visible after a few initial swipes. I have not been able to find any documentation or examples on how the &apo ...

What is the ideal way to iterate a loop in jQuery while using setTimeout?

Currently, I'm working on a table and attempting to develop a bookmarklet that will automatically click on each row and perform some actions based on a timer. The loading time for each tab is quite long, but when I focus on just one row, the code work ...

Error message: The variable THREE has not been defined in a Rails Project utilizing the threejs-rails gem

Currently, I am working on a project using Ruby on Rails and incorporating three.js. I have successfully installed the corresponding gem, and everything appears to be functioning properly. However, an error is being thrown in the JavaScript: Uncaught Refe ...