jQuery ui sortable tablerows refresh number position inside

后端 未结 2 792
悲哀的现实
悲哀的现实 2021-02-05 15:01

In a html table I have in every row a cell with its own position number. How can I refresh this position number correctly after sorting with jQueryUI?

This is my simple

2条回答
  •  日久生厌
    2021-02-05 15:54

    Do the following after sorting ..

    $("table tbody").sortable({ 
        update: function(event, ui) {  
            $('table tr').each(function() {
                $(this).children('td:first-child').html($(this).index())
            });
        },
        helper: fixHelper
    }).disableSelection();
    

    you can try (untested) : instead of $('table tr').each use $(this).parents('table').find('tr').each

    Explanation.. It loops through each of the tr tags within table and then changes the content of first td-child with the index value of tr

提交回复
热议问题