I need to change the order of columns in a table in html / js dynamically, you can tell me how to do it?
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🙂).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With