Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change table columns order

I need to change the order of columns in a table in html / js dynamically, you can tell me how to do it?

like image 950
Frayx Avatar asked Mar 28 '11 19:03

Frayx


People also ask

How do I change the order of columns in a mysql table?

When you hover over the table name you would see three icons, click on settings (that is the one in the middle) or you can right-click and select Alter Table , then click on the column and drag it to the position you want your column to be. on your bottom right you will see apply (click and apply🙂).

Can we change the order of columns in a table in Oracle?

For certain tables, you can change the order in which columns are displayed by clicking and dragging a column heading to a new position. In other tables, you can use the Reorder Columns dialog to change the position of the columns.


1 Answers

If you only require to simply move a column without any fancy drag-drop animation, the following JS should do the trick:

<script type="text/javascript">     $(function() {         jQuery.each($("table tr"), function() {              $(this).children(":eq(1)").after($(this).children(":eq(0)"));         });     }); </script> 

Replacing the numbers as necessary. The concept works

It seems that writing this as a one liner isn't really possible. including td in the selector, even with the row selector seems to hold each td on a separate index, ignoring rows.

A jQuery grid plugin should do the trick otherwise. Although I have no experience with such plugins.

like image 52
Hux Avatar answered Sep 20 '22 01:09

Hux