Frage

I got 2 tables "newsTable" and "eventsTable". I want to make them sortable with jquery.sortable plugin, its working pretty ok but when i click on any column its sorting twice, so in fact im getting the starting position :/ How to solve the problem? Why columns are being sorted twice? I had no problem with that when I had only one table in page, now I have 2 and problems have came :(

<script>
$(document).ready(function() 
    { 
        $("#newsTable").tablesorter(); 
    } 
); 

$(document).ready(function() 
    { 
        $("#newsTable").tablesorter( {sortList: [[1,0]]} ); 
    } 
);

$(document).ready(function() { 
    $("table") 
    .tablesorter({widthFixed: true, widgets: ['zebra']}) 
    .tablesorterPager({container: $("#pager1")}); 
}); 

$(document).ready(function() 
    { 
        $("#eventsTable").tablesorter(); 
    } 
); 

$(document).ready(function() 
    { 
        $("#eventsTable").tablesorter( {sortList: [[1,0]]} ); 
    } 
);

$(document).ready(function() { 
    $("table") 
    .tablesorter({widthFixed: true, widgets: ['zebra']}) 
    .tablesorterPager({container: $("#pager2")}); 
}); 
</script>
War es hilfreich?

Lösung

You are adding the tablesorter four times for both tables, hence the sorting occurs four times.

Try calling $(document).ready() only once:

$(document).ready(function()
{
    $("#newsTable").tablesorter( 
    {
        widthFixed: true, 
        widgets: ['zebra'],
        sortList: [[1,0]]
    }).tablesorterPager(
    {
        container: $("#pager1"),
        size: 5
    }); 

    $("#eventsTable").tablesorter( 
    {
        widthFixed: true, 
        widgets: ['zebra'],
        sortList: [[1,0]]
    }).tablesorterPager(
    {
        container: $("#pager2"),
        size: 5
    }); 
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top