Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
sorting column is not working in bootstrap 5

I have created a table with bootstrap 5 but once I try to sort the first column I didn't get any change. this is how the table looks like:

1

The table is defined like so:

<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>

What I need is to sort all the table respect to the first column "Event date&time".

Thank you very much for any suggestion

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You cannot sort a table with Bootstrap 5 - Tables. Maybe you use something else than this Bootstrap ? Otherwise you can see Datatables for sorting tables.

about 4 years ago · Santiago Trujillo Report

0

In the end I found a way to sort the data in the table as I wanted.

Basically I had to gather every row of the column in an array of dictionary so that:

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

Then I sorted the array using the id for instance with:

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

In this way I had the correctly formatted table sorted by Id in this example

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!