Re-order table columns?

后端 未结 4 866
北荒
北荒 2021-02-03 10:55

Does anyone know a way to re-order table columns, using jQuery?

I don\'t mean sort - I mean dynamically move entire columns left or right in a table.

I\'m aware

4条回答
  •  鱼传尺愫
    2021-02-03 11:40

    This code should work for you.

    $("table tr").each(function () {
        $(this).find("td").eq(1).after($(this).find("td").eq(0));
    });
    


    Edit: If you assign $(this).find("td") to a variable this would give better performance. But the context was down to a single tr. So i assumed it would be enough just to give the idea.

    $("table tr").each(function () {
        var rows = $(this).find("td");
        rows.eq(1).after(rows.eq(0));
    });
    

提交回复
热议问题