In the javascript code block below you can see the default $.tablesorter.characterEquivalents table and an example of how to extend it to include other equivalents.
If you have a specific language requirement, please refer to the Language wiki pages to see if it is there. If not, please consider sharing the code or even just share the character equivalents themselves.
One custom sort used here is from the original tablesorter plugin v2.0.3. Sort the first "Plain Text Sort" column to see how it sorts alphanumeric data.
This option is not part of the original plugin (v2.2).
This example demonstrates that common table values are auto-detected (including plain text, currency, percentages, and positive & negative numbers), so there is no need to set a specific parser unless you notice an issue with how a column is sorting.
Issues may arise if a column contains mixed data, e.g. "N/A" is located at the top of a numeric column; in this case the column will be detected as a text column and not a numeric column. If issues occur, add a sorter-digit class name to that header cell.
As of v2.16.3, there is a built-in 500 millisecond delay before the processing icon will show. If the sort has completed within that time, the icon will not appear.
There is an issue with the processing icon not appearing at all, or the animation appears frozen when processing data in very large tables. This is due to javascript only being able to process one thread at-a-time; If you know of a solution or work-around please add a comment or contribute a fix!
Test the sortReset option by clicking on any column at least three times. It should sort in the sortInitialOrder direction on the first click, the opposite direction on the second click, then reset to the original sort order on the third click. This cycle repeats on subsequent sorts.
Test the sortRestart option by clicking on any unsorted column to see that it will always restart from the sortInitialOrder.
This method of writing custom parsers will NOT work with the original tablesorter 2.0.5b plugin because the format function does not consistently provide the cell and cellIndex parameters.
NOTE! Assigning the parser using a class name was added in version 2.0.11 (it is not part of the original plugin; use the headers option in older versions).
-
Automatic resorting after "updateCell" is triggered was added in version 2.0.14.
-
+
Demo
diff --git a/docs/example-widget-align-character.html b/docs/example-widget-align-character.html
index 2cbc738e..8e73d2b3 100644
--- a/docs/example-widget-align-character.html
+++ b/docs/example-widget-align-character.html
@@ -122,13 +122,13 @@ td:nth-child(3) .ts-align-right i {
</span>
</td>
When this option is set with some HTML:
-
The first step is to decide what you want your filter to do.
+
The first step is to decide what you want your filter to do.
+
Should it look for a symbol at the beginning, middle or end of the filter?
+
Does the designator need spaces around it (e.g. " and " or " or ") to prevent problems? You wouldn't be able to find the country of "Andorra" if the "and" or "or" designators didn't require spaces.
+
Make sure to name your filter so that it doesn't interfere with already existing ones, unless your filter is meant to replace an existing one. See the "Built-in Filters" section for a full list of filter function names.
+
Within your filter, first test for your designator symbol.
-
Should it look for a symbol at the beginning, middle or end of the filter?
-
Does the designator need spaces around it (e.g. " and " or " or ") to prevent problems? You wouldn't be able to find the country of "Andorra" if the "and" or "or" designators didn't require spaces.
-
Make sure to name your filter so that it doesn't interfere with already existing ones, unless your filter is meant to replace an existing one. See the "Built-in Filters" section for a full list of filter function names.
-
Within your filter, first test for your designator symbol.
+
If it exists within the filter, then do your comparison and return a boolean of true or false.
+
Four arguments are passed to the filter function:
-
If it exists within the filter, then do your comparison and return a boolean of true or false.
-
Four arguments are passed to the filter function:
-
-
filter - The exact text from the filter input (e.g. ^h).
-
iFilter - The text from the filter in all lower case for case insensitive searches.
-
exact - The exact (or parsed) text from the current table cell; the parsed text is passed when the column has a "filter-parsed" class name set.
-
iExact - The exact (or parsed) text in all lower case for case insensitive searches.
-
-
-
If your designator doesn't exist, you *must* return null to allow comparisons with other filter types.
-
Here is a basic example with extensive comments:
-
// search for a match from the beginning of a string
+
filter - The exact text from the filter input (e.g. ^h).
+
iFilter - The text from the filter in all lower case for case insensitive searches.
+
exact - The exact (or parsed) text from the current table cell; the parsed text is passed when the column has a "filter-parsed" class name set.
+
iExact - The exact (or parsed) text in all lower case for case insensitive searches.
+
+
+
If your designator doesn't exist, you *must* return null to allow comparisons with other filter types.
+
+
+
Here is a basic example with extensive comments:
+
// search for a match from the beginning of a string
// "^l" matches "lion" but not "koala"
$.tablesorter.filter.types.start = function( filter, iFilter, exact, iExact ) {
// test for filter type designator. In this example, "^" must be at the beginning of the filter
@@ -167,7 +168,8 @@ $.tablesorter.filter.types.start = function( filter, iFilter, exact, iExact ) {
}
// ALWAYS return null if your custom filter type doesn't match
return null;
-};
+};
+
diff --git a/docs/example-widget-filter-custom.html b/docs/example-widget-filter-custom.html
index 50aaa27c..56cb8844 100644
--- a/docs/example-widget-filter-custom.html
+++ b/docs/example-widget-filter-custom.html
@@ -237,9 +237,9 @@
// Note that only the normalized (n) value will contain numerical data
// If you use the exact text, you'll need to parse it (parseFloat or parseInt)
4 : {
- "< $10" : function(e, n, f, i, $r) { return n < 10; },
- "$10 - $100" : function(e, n, f, i, $r) { return n >= 10 && n <=100; },
- "> $100" : function(e, n, f, i, $r) { return n > 100; }
+ "< $10" : function(e, n, f, i, $r) { return n < 10; },
+ "$10 - $100" : function(e, n, f, i, $r) { return n >= 10 && n <=100; },
+ "> $100" : function(e, n, f, i, $r) { return n > 100; }
}
}
See the "Filter function information" section below.
To change an input from searching one column (or all columns) to search any other column, call the $.tablesorter.bindSearch function to update the external inputs, even if the inputs are set using the filter_external option. Pass an additional false flag as the last parameter to force the inputs to update.