1

I want to sort a data table in a jsp page, by clicking on the columns. Probably with a javascript or JQuery. I only have the headers, data is coming from database

   <table name="tablesorter" id="tablesorter" class="tablesorter"       cellspacing="0"         width="720"
style="table-layout:fixed;">
<thead>
<tr>
    <th width="90" class="tableRubrikCell">Anv.namn</th>
    <th width="115" class="tableRubrikCell">Namn</th>
    <th width="135" class="tableRubrikCell">Roller</th>
    <th width="60" class="tableRubrikCell">Ansvarig</th>
    <th width="90" class="tableRubrikCell">Skapad&nbsp;datum</th>
    <th width="75" class="tableRubrikCell">Giltig&nbsp;tom</th>
    <th width="120" class="tableRubrikCell">E-postadress</th>
    <th width="40" class="tableRubrikCell">Ta&nbsp;bort</th>
</tr>
</thead>
brbe24
  • 23
  • 1
  • 5

2 Answers2

0

You can use Tablesorter plugin for jquery. the general idea would be to get the data from the database with some initial sort order and set the same in the table sorter initialization. Docs for tablesorter.

kedar
  • 273
  • 4
  • 9
0
  1. Get the table rows as array of json.

  2. Sort the array on the field which you want to sort.

  3. Iterate through the array of json and append tr to the tbody.

For sorting you can refer this SO link

Simple function to sort an array of objects

Community
  • 1
  • 1
Konza
  • 2,143
  • 17
  • 30