Help:Wiki University HTML-- Tables - Sorting





<< Previous Chapter Next Chapter >>

TABLE SORTING
Sometimes tables can get really long and finding what you are looking for can be hard particularly if they are not in any kind of order such as alphabetical. To help with this we can use a "class" called sorting. This will allow us to sort alphabetically any particular column.  <table class="sortable" style="border:1px solid red: width:100% ... Here is what the table will look like with the sorting class in the beginning heading tags:
 * It is placed in the beginning table tag like so:
 * You place the "class" before the inline style code.
 * The class has to have a space to separate it from inline style codes.

If you click on these icons in any of the columns you will see the columns arrange themselves in alphabetical order.
 * NOTICE a small hour glass like icon has appeared alongside the headings. These icons appear on the first row regardless of the kind of row it is.

ROWS STAY TOGETHER
This is important. If you have a table of names and addresses, you will want the addresses to stay with the names if they were sorted alphabetically. This sorting attribute allows you to add items without having to worry about the order.
 * PLEASE NOTICE CAREFULLY the items in the rows stay with the item in the column that you have alphabetically rearranged. It does not matter which column you click.

TRY THESE OUT . . . ..


 Exercises Check your answers
 * Take our Healthy Foods table and add another row.
 * Now make the table sortable.

 Quick Quiz
 * When you click the sorting icon, the sorting is permanent.
 * A. True
 * B. False


 * When you add items to a table, you need to insert the item in the table where it is supposed to go if you want your table in alphabetical order even with the sorting class applied.
 * A. True
 * B. False


 * Sorting will revert back to the original order if you leave the page the table is on.
 * A. True
 * B. False

Check your answers

<< Previous Chapter Next Chapter >>