Notes

  • This demo uses a modified version of the jQuery UI Dragtable widget (beta) to work with tablesorter.
  • This mod has been tested with the following widgets: alignChar, columns, cssStickyHeaders, editable, filter, grouping, headerTitles, math, output, pager print, reflow, resizable, repeatHeaders, staticRow, uitheme & zebra.
  • This mod does not currently work with the following widgets:
    • chart - needs more work to be compatible.
    • columnSelector - needs more work - making this compatible will require significant changes to the dragtable core.
    • saveSort - this saves the newly moved sorted column properly, but on page reload the column order is restored so it sorts the incorrect column.
    • scroller - way too much work to make this compatible.
    • stickyHeaders - needs more work - can't get the drag handle in the cloned sticky header from passing the mousedown on to the original drag handle.
  • Any widgets not listed above can be assumed to be incompatible, for now.

Tablesorter setup

A complete javascript example can be found in the demo section, below the table.

To use this mod:
  • Initialize the dragtable mod script first, then initialize tablesorter.
  • Warning! When setting up the initialization code, make sure that the dragtable sortClass option exactly matches the tablesorter selectorSort option, or the table will be unsortable.
    $('table')
      .dragtable({ sortClass: '.sorter' }) // this is already the default value
      .tablesorter({ selectorSort: '.sorter' }); // this default value is 'th, td'
  • Warning! Do not reference a column using jQuery data (e.g. $('th:contains(Name)').data('sorter', 'text');) or by it's zero-based index(1) because these references do not get updated after a column move!

    Instead, use one of the following methods (these examples set the column parser):

    Set parser by data-attribute or header class

    <tr>
    	<th class="col-id" data-sorter="digit">...</th> <!-- parser set by data-attribute -->
    	<th class="col-name drag-enable sorter-text">...</th> <!-- parser set by header class -->
    	<th class="col-date drag-enable">...</th> <!-- parser set by headers option (see below) -->
    </tr>

    Or, set parser by headers option

    $('table').tablesorter({
    	headers : {
    		'.col-date' : { sorter : 'shortDate' }
    	}
    });
  • In order to get dragtable to work, the mod will add a div to act as a dragable handle and wrap the header text in a div(2) which needs to be targeted by the selectorSort option to make it clickable for sorting.

    The resulting HTML may look like this:
    <tr>
    	<th class="col-id" data-sorter="digit">
    		<div class="table-handle-disabled"></div>
    		<!-- clicking on the "sort" wrapper below will not trigger a sort, because the cell is not set to sort -->
    		<div class="sorter">9999</div>
    	</th>
    	<th class="col-name sorter-text drag-enable">
    		<div class="table-handle"></div>
    		<div class="sorter">Name</div>
    	</th>
    	<th class="col-date drag-enable">
    		<div class="table-handle"></div>
    		<div class="sorter">1/1/2015</div>
    	</th>
    </tr>
(1) Options that use a column index (such as the sortList), or an array of settings (like the resizable_widths option) are updated internally by the mod.

(2) The class name for the dragable handle is set by the dragtable dragHandle option & the class name for the clickable div wrapping the header text is set by the dragtable sortClass option.

Demo

Student Grades
Name (0) Major (1) Sex (2) English (3) Japanese (4) Calculus (5) Geometry (6)
NameMajorSexEnglishJapaneseCalculusGeometry
Student01 (0)Languages (1)male (2)80 (3)70 (4)75 (5)80 (6)
Student02Mathematicsmale908810090
Student03Languagesfemale85958085
Student04Languagesmale6055100100
Student05Languagesfemale68809580
Student06Mathematicsmale1009910090
Student07Mathematicsmale85689090
Student08Languagesmale100909085
Student09Mathematicsmale80506575
Student10Languagesmale8510010090
Student11Languagesmale8685100100
Student12Mathematicsfemale100757085
Student13Languagesfemale1008010090
Student14Languagesfemale50455590
Student15Languagesmale953510090
Student16Languagesfemale100503070
Student17Languagesfemale801005565
Student18Mathematicsmale30495575
Student19Languagesmale68908870
Student20Mathematicsmale40454080

HTML


		

Javascript


		

Optional CSS