Change table columns order

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.

Leave a Comment