Reputation: 1
I'm not an expert of HTML, Javascript and CSS, I have the following situation:
<div class="table">
<table class="display-table">
<thead>
<tr>
<th class="col-table">Index</th>
<th class="col-table">feature</th>
<th class="col-table">other columns ...</th>
</tr>
</thead>
other code
</table>
</div>
There's a way to order the table according to the Index column (that contains integer numbers)? And is it possible to do it from HTML or should I write some other code in js? Right now, each time I'm adding a new record in the table, it is putted at the end of the table, even if it present an index lower than the last one. Thank you!
Upvotes: 0
Views: 406
Reputation: 808
There is currently no way of sorting a table with HTML5 or CSS alone.
You will have to write some JS Code or get one of the many libraries having this functionality.
An example is jQuery (which also provide many additional functionality without diving into JS too deeply - be aware, that does not mean your shouldn't do so!). There are many tutorials around, like this one
If you want to sort a table with vanilla code, take a look here:
w3Schools - How TO - Sort a Table
Basically you need a callback, which is triggered on new row, and on data loaded.
Upvotes: 1