It depends on nature of your data. The answer varies based on its size and data type. I saw a lot of SQL solutions based on ORDER BY
. I would like to suggest javascript alternatives.
In all answers, I don't see anyone mentioning pagination problem for your future table. Let's make it easier for you. If your table doesn't have pagination, it's more likely that a javascript solution makes everything neat and clean for you on the client side. If you think this table will explode after you put data in it, you have to think about pagination as well. (you have to go to first page every time when you change the sorting column)
Another aspect is the data type. If you use SQL you have to be careful about the type of your data and what kind of sorting suites for it. For example, if in one of your VARCHAR columns you store integer numbers, the sorting will not take their integer value into account: instead of 1, 2, 11, 22
you will get 1, 11, 2, 22
.
You can find jquery plugins or standalone javascript sortable tables on google. It worth mentioning that the <table>
in HTML5 has sortable
attribute, but apparently it's not implemented yet.