jQuery tablesorter plugin - perform an action AFTER table is sorted

tablesorter example
jquery table sort
jquery sort table without plugin
jquery tablesorter filter
tablesorter sortlist
tablesorter example jsfiddle
jquery tablesorter pager
jquery tablesorter not working

I have a table which is sorted successfully using the tablesorter plugin. However, I want to highlight the text in a particular text field in a particular row. It has a unique ID, but when I place my code after the sorting code it doesn't work. Here's my code:

jQuery(document).ready(function() { 
  jQuery("#filetable").tablesorter({
    sortList: [[3,1]],
    widgets: ['zebra'],
    testExtraction: "complex"
  });
  //my new code which doesn't work as expected
  if(jQuery("#new_foldername").length > 0){ 
    jQuery("#new_foldername").focus(function() { jQuery(this).select(); } ); 
  }
}); 

If I stick an alert just after the check to see if the #new_foldername exists, I see the alert, and I see the text highlighted in the background (so my code to highlight the text works). When I click to close the alert, then the table finishes sorting... and the text is not highlighted any more.

Any ideas what might be happening?

it seems the sorting is happening asynchronously. the documentation provides a hook called 'sortEnd' where you probably want to run your highlighting code. see example from http://tablesorter.com/docs/example-triggers.html

$(document).ready(function() { 
    // call the tablesorter plugin, the magic happens in the markup 
    $("table").tablesorter(); 

    //assign the sortStart event 
    $("table").bind("sortStart",function() { 
        $("#overlay").show(); 
        }).bind("sortEnd",function() { 
        $("#overlay").hide(); 
    }); 
}); 

jQuery tablesorter 2.0, I have a table which is sorted successfully using the tablesorter plugin. However, I want to highlight the text in a particular text field in a particular row. It has a  Hi, I'm having trouble to enable sorting on the table once the ajax creates the table dynamically. I have this form: <form method="get" action="getTable.php" sort table after ajax creates table using jquery plug-in tablesorter - jQuery Forum

Thanks Robert,

Unfortunately sortEnd is only run when you click on a column heading to sort by. It doesn't work on the initial sort...

Instead I created a new widget like so:

jQuery.tablesorter.addWidget({ 
  id: "highlightNewFolder", 
  // format is called when the on init and when a sorting has finished 
  format: function(table) { 
    if(jQuery("#new_foldername").length > 0){  
      jQuery("#new_foldername").focus();
    }
  } 
});

This now works. Unfortunately I had to drop the selecting/highlighting of all the text. For some reason when the code had 'select()' within it, not even the focusing worked:

jQuery("#new_foldername").focus(function() { jQuery(this).select(); } ); 

If anyone has any ideas on how to focus AND highlight all text, then that would be much appreciated!

jQuery tablesorter 2.0, tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and You need Javascript enabled to run these samples, just like you and your but the data still needs to be parsed, so the delay is still present upon initial sort. namespace for each table; it is used when binding to event listeners (v2.15.7). by Christian Bach tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes. tablesorter can successfully parse and sort many types of data including linked data in a cell.

You can use the initialized callback function (or bind to the tablesorter-initialized event) (source) Note: Those only work on Mottie's fork of tablesorter, not the original (v2.0.5).

jQuery(document).ready(function() {
    jQuery("#filetable").tablesorter({
        sortList: [[3, 1]],
        widgets: ['zebra'],
        testExtraction: "complex",
        initialized: function() {
            if (jQuery("#new_foldername").length > 0) {
                jQuery("#new_foldername").focus(function() {
                    jQuery(this).select();
                });
            }
        }
    });
});

Sorting Tables with Tablesorter, call the tablesorter plugin, the magic happens in the markup $("table") .​tablesorter({ assign the sortStart event Sort Events. Sort events will appear here. tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes. tablesorter can successfully

Maybe something has changed. The answers did not work for me, but this does:

$("#filetable").tablesorter().bind("sortEnd", function (e, t) {
    customHilite();
});

Zebra plugin did not work for me. maybe because of the way I was filtering rows.

tablesorter, This article describes the Tablesorter jQuery plugin that is used to In this article I'll introduce you to Tablesorter (actually a fork of it), a jQuery plugin for client-side table sorting. You have to import the JavaScript file after the jQuery library: To let you see this plugin in action, we'll use the following table:. Stupid jQuery Table Sort. This is a stupid jQuery table sorting plugin. Nothing fancy, nothing really impressive. Overall, stupidly simple. Requires jQuery 1.7 or newer.

jQuery plugin: Tablesorter 2.0, tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and This tells tablesorter to sort on the first and second column in ascending order. You need Javascript enabled to run these samples, just like you and your users will to the table, but the widget will not continue to be applied after each sort. tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes. tablesorter can successfully parse and sort many types of data including linked data in a cell.

Applied jQuery: Develop and Design, tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and TBODY You need Javascript enabled to run these samples, just like you and your users will For example, can be used to sort people alphabetically after some other trigger a refresh widget event $('table').trigger('refreshWidgets', [​doAll,  Flexible Client-Side Table Sorting Plugin - tablesorter 17785 views - 03/04/2020; Excel-like CRUD Data Grid Library - Handsontable 56910 views - 02/19/2020; Feature-rich Data Table Plugin For Bootstrap 4/3/2 24092 views - 02/11/2020; Highly Customizable Table Sort Plugin With jQuery - Stupid Table 4565 views - 12/06/2019

Jquery sorting div, tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and You need Javascript enabled to run these samples, just like you and your but the data still needs to be parsed, so the delay is still present upon initial sort. Click on the link in the event column to reveal full details (or toggle|show|hide all)​  Tablesorter is a simple jQuery plugin that provides dynamic row sorting based on the values of one or more given columns, and also offers the possibility to paginate tables created using the HTML

Comments
  • Thanks dude. Wow that was a while ago I posted this! I've since moved onto using Datatables now, so unable to test your suggestion, but it sounds plausible...!