JQuery tablesorter plugin not working after AJAX call

In my code, I used jQuery table sorter plugin. It works fine until I make an ajax request to dynamically load the table data. I use combined fields to filter the contents of a table using ajax. I read a few posts that said using $("table").trigger("update");could solve my problem. I tried this with my code, but the problem is still there.

Is there any other way to solve this problem? Please help me figure out the solution. I am really stuck badly. Any help would be greatly appreciated. Below is my code:

$(document).ready(function () {
    $("#myTable").tablesorter({
        widthFixed: true,
        widgets: ['zebra'],
        headers: {
            0: {
                sorter: false
            }
        }
    }).tablesorterPager({
        container: $("#pager")
    });

    $("#tag").change(function (event) {
        $('#myTable').trigger("update");
        $("#myTable").tablesorter();
    });
});

Here, the tag is the identifier of the combined field with the name tag, and myTable is the identifier of the table with the plugin for the sorter player.

+3
6

, AJAX, ASP.NET UpdatePanel, jQuery AJAX.

script

:
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(function(sender, args) {
    // Code to rebind your UI
});

: , ASP.NET AJAX

+1

DOM JavaScript. jQuery , "" . AJAX , javascript document.ready().

+1

tablesorter .

, , .

$(document).ready(function () {
    function resortTable(){ 
          $("#myTable").tablesorter({
            widthFixed: true,
            widgets: ['zebra'],
            headers: {
                0: {
                    sorter: false
                }
            }
        }).tablesorterPager({
            container: $("#pager")
        });
    }

        $("#tag").change(function() {
            resortTable();
        });
});
+1

, $('#myTable').trigger("update");, , AJAX. ASP.NET AJAX, ericphan. jQuery AJAX, - :

$.get('http://site.com/request-address', function(data) {

    // Code you're using to replace the contents of the table

    // Code to rebind the tablesorter
    $('#myTable').trigger("update");
    $("#myTable").tablesorter();
});

, tablesorter , , .

0

, , , , - . ,

$('#myTable').tablesorter();

AJAX.

0
source

Source: https://habr.com/ru/post/1753849/


All Articles