mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
textExtraction function updates
This commit is contained in:
parent
04aacd5449
commit
930aad6d3a
@ -34,6 +34,13 @@ Included all original [document pages](http://mottie.github.com/tablesorter/docs
|
||||
|
||||
View the [complete listing here](http://mottie.github.com/tablesorter/changelog.txt).
|
||||
|
||||
#### Version 2.1.2 (3/11/2012)
|
||||
|
||||
* Added `table` and `cellIndex` variables to the `textExtraction` function to allow using a more general function for text extraction.
|
||||
* Empty cells will no longer skip the parser allowing extracting data attributes.
|
||||
* This was only an issue on table cells with no text.
|
||||
* Added a demo to the [demos wiki page](https://github.com/Mottie/tablesorter/wiki) whichs allows [dynamic sorting of checkboxes](http://jsfiddle.net/Mottie/vCTHw/18/).
|
||||
|
||||
#### Version 2.1.1 (3/8/2012)
|
||||
|
||||
* Renamed `filter_fromStart` to `filter_startsWith`.
|
||||
@ -174,12 +181,3 @@ View the [complete listing here](http://mottie.github.com/tablesorter/changelog.
|
||||
#### Version 2.0.30.1 (2012-2-20)
|
||||
|
||||
* Modified the "filter" widget to disable the input window instead of setting it with display none. Now the input is disabled and a "disabled" class is applied to allow for further styling.
|
||||
|
||||
#### Version 2.0.30 (2012-2-20)
|
||||
|
||||
* Fixed the total mess I just made with the addWidget init functionality... I need a vacation :P
|
||||
|
||||
#### Version 2.0.29 (2012-2-20)
|
||||
|
||||
* Fixed a problem with the addWidget init function which apparently was always being called, even if you didn't want it! Fix for [issue #28](https://github.com/Mottie/tablesorter/issues/28). Thanks to thezoggy for helping with troubleshooting!
|
||||
* Minor cleanup of sorting class names code.
|
||||
|
132
changelog.txt
132
changelog.txt
@ -1,5 +1,137 @@
|
||||
TableSorter Change Log
|
||||
|
||||
Version 2.1.2 (3/11/2012)
|
||||
============================
|
||||
|
||||
* Added `table` and `cellIndex` variables to the `textExtraction` function to allow using a more general function for text extraction.
|
||||
* Empty cells will no longer skip the parser allowing extracting data attributes.
|
||||
* This was only an issue on table cells with no text.
|
||||
* Added a demo to the [demos wiki page](https://github.com/Mottie/tablesorter/wiki) whichs allows [dynamic sorting of checkboxes](http://jsfiddle.net/Mottie/vCTHw/18/).
|
||||
|
||||
Version 2.1.1 (3/8/2012)
|
||||
============================
|
||||
|
||||
* Renamed `filter_fromStart` to `filter_startsWith`.
|
||||
* Fixed an issue with `sortRestart` not working properly.
|
||||
* In turn, `sortReset`, `lockOrder` and `sortInitialOrder` were modified with this change and were made sure to all work properly.
|
||||
* The `sortInitialOrder` will work in either the main options or specifically within the headers option when a particular column needs a different initial sort order.
|
||||
* Added a [sortReset/sortRestart](http://mottie.github.com/tablesorter/docs/example-option-sortreset-sortrestart.html) demo.
|
||||
* Resolves [issue #30](https://github.com/Mottie/tablesorter/issues/29).
|
||||
* Updated pager plugin to better work with the sticky header widget.
|
||||
|
||||
Version 2.1 (3/7/2012)
|
||||
============================
|
||||
|
||||
* Added `selectorRemove` option
|
||||
* Any table row with this css class will be removed from the table prior to updating the table contents.
|
||||
* The reason this was added was in case a widget or some other script adds rows to the table for styling, or something else. If a table update is triggered (`$(table).trigger('update');`), all rows in the table will be included in the update.
|
||||
* The [writing custom widgets](http://mottie.github.com/tablesorter/docs/example-widgets.html) demo has been updated to include this class name.
|
||||
* The pager plugin update also uses this to remove the row added by the new `fixedHeight` option.
|
||||
* It's default value is `tr.remove-me`, so it can be modified to remove more than just rows.
|
||||
|
||||
* Fixed a bug that broke the plugin if you set `sorter: true` in the header options.
|
||||
|
||||
* Pager plugin update
|
||||
* Ajax
|
||||
* The pager plugin will now interact with a database via JSON. See [demo here](http://mottie.github.com/tablesorter/docs/example-pager-ajax.html).
|
||||
* Added `ajaxUrl` option which contains the variables `{page}` and `{size}` which will be replaced by the plugin to obtain that data.
|
||||
|
||||
```javascript
|
||||
ajaxUrl : "http:/mydatabase.com?page={page}&size={size}"
|
||||
```
|
||||
|
||||
* Another option named `ajaxProcessing` was included to process the data before returning it to the pager plugin. Basically the JSON needs to contain the data to match the example below. An additional required variable is the total number of records or rows needs to be returned.
|
||||
|
||||
```javascript
|
||||
// process ajax so that the data object is returned along with the total number of rows
|
||||
// example: { "data" : [{ "ID": 1, "Name": "Foo", "Last": "Bar" }], "total_rows" : 100 }
|
||||
ajaxProcessing: function(ajax){
|
||||
if (ajax && ajax.hasOwnProperty('data')) {
|
||||
// return [ "data", "total_rows" ];
|
||||
return [ ajax.data, ajax.total_rows ];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
* I tried to make the plugin interact with a database as flexible as possible, but I'm sure I haven't covered every situation. So any and all feedback is welcome!
|
||||
* Also, much thanks to [kachar](https://github.com/kachar) for the [enhancement request](https://github.com/Mottie/tablesorter/issues/31) and willingness to help test it!
|
||||
|
||||
* Removed `positionFixed` and `offset` options.
|
||||
* Added `fixedHeight` option which replaces the `positionFixed` and `offset` options by maintaining the height of the table no matter how few rows are showing. During testing, it displayed some odd behaviour after adding or deleting rows, but it should have been fixed... just please keep an eye out ;).
|
||||
* The pager now adds all of its options to the table configuration options within an object named "pager". Basically what this means is that instead of add all of the pager options to be mixed in with the tablesorter options, the pager options have been isolated and can be found by typing this into the browser console: `$('table')[0].config.pager`.
|
||||
|
||||
* **Storage** function added named `$.tablesorter.storage` for use in widgets
|
||||
* It is used by various widgets to save data to either local storage (if available) or cookies.
|
||||
* This function needs to use `JSON.stringify()` which is [not supported by IE7](http://caniuse.com/#search=json). If you need to support IE7, then include this library: [JSON-js](https://github.com/douglascrockford/JSON-js).
|
||||
* Use the function with your own custom widgets as follows:
|
||||
|
||||
```javascript
|
||||
// *** Save data (JSON format only) ***
|
||||
// val must be valid JSON... use http://jsonlint.com/ to ensure it is valid
|
||||
var val = { "mywidget" : "data1" }; // valid JSON uses double quotes
|
||||
// $.tablesorter.storage(table, key, val);
|
||||
$.tablesorter.storage(table, 'tablesorter-mywidget', val);
|
||||
|
||||
// *** Get data: $.tablesorter.storage(table, key); ***
|
||||
v = $.tablesorter.storage(table, 'tablesorter-mywidget');
|
||||
// val may be empty, so also check for your data
|
||||
val = (v && v.hasOwnProperty('mywidget')) ? v.mywidget : '';
|
||||
alert(val); // "data1" if saved, or "" if not
|
||||
```
|
||||
|
||||
* Added an option named `widgetOptions`:
|
||||
* This is a move to store all widget specific options in one place so as not to polute the main table options.
|
||||
* All current widgets have been modified to use this new option.
|
||||
* Only one widget option, `widgetZebra` will be retained for backwards compatibility with the original plugin.
|
||||
* More details for each widget are explained below.
|
||||
|
||||
* **Zebra** widget:
|
||||
* Added `zebra` options to the new `widgetOptions`.
|
||||
|
||||
```javascript
|
||||
widgetOptions : {
|
||||
zebra : [ "even", "odd" ]
|
||||
}
|
||||
```
|
||||
|
||||
* This replaces `widgetZebra: { css: [ "even", "odd" ] }`, but if the `widgetZebra` option exists, it will over-ride this newer `widgetOptions.zebra` option in order to maintain backwards compatibility.
|
||||
|
||||
* **UI Theme** widget:
|
||||
* Changed css class of div wrapping the contents of each header cell from "inner" to "tablesorter-inner".
|
||||
* Added "ui-state-default" to the table head columns. Thanks to [Raigen](https://github.com/Raigen) for [sharing the code](https://github.com/Mottie/tablesorter/pull/33)!
|
||||
* Moved `widgetUitheme` option into the new `widgetOptions`.
|
||||
|
||||
```javascript
|
||||
widgetOptions : {
|
||||
// adding zebra striping, using content and default styles - the ui css removes the background from default
|
||||
// even and odd class names included for this demo to allow switching themes
|
||||
zebra : ["ui-widget-content even", "ui-state-default odd"],
|
||||
|
||||
// change default uitheme icons - find the full list of icons here: http://jqueryui.com/themeroller/ (hover over them for their name)
|
||||
// default icons: ["ui-icon-arrowthick-2-n-s", "ui-icon-arrowthick-1-s", "ui-icon-arrowthick-1-n"]
|
||||
// ["up/down arrow (cssHeaders/unsorted)", "down arrow (cssDesc/descending)", "up arrow (cssAsc/ascending)" ]
|
||||
uitheme : ["ui-icon-carat-2-n-s", "ui-icon-carat-1-s", "ui-icon-carat-1-n"]
|
||||
}
|
||||
```
|
||||
|
||||
* **Filter** widget changes:
|
||||
* Added a new filter widget specific option `widgetOptions.filter_fromStart` which makes the filter only work from the first letter.
|
||||
* Added a `widgetOptions.filter_cssFilter` option which now contains the class name added to the filter row and each input within it. Previously the class name used was "filters" for the row and "filter" for the input, now both are "tablesorter-filter". Thanks to [cr125rider](https://github.com/cr125rider) for [sharing a code fix](https://github.com/Mottie/tablesorter/issues/32)!
|
||||
* Added css3 box sizing to allow a better fitting filter box. Thanks to [thezoggy](https://github.com/thezoggy) for sharing the code!
|
||||
* The css changes were also added to the blue, green and UI style sheets.
|
||||
* Updated the filter widget demo with the available options described above; this includes the `widgetOptions.filter_childRows` option which was previously undocumented, recently renamed.
|
||||
|
||||
* **Resizable Columns** Widget changes:
|
||||
* The resized column width is now saved using the `$.tablesorter.storage()` function (optional)
|
||||
* If the storage function doesn't exist, the widget will still function, but just not save the column width.
|
||||
|
||||
* **Save Sort** Widget changes:
|
||||
* Modified to now use the `$.tablesorter.storage()` function (required)
|
||||
* The storage function is required for this widget to work properly.
|
||||
* Previous saved data is not compatible with the changes made and will be ignored.
|
||||
|
||||
* Updated all docs demos to use jQuery 1.7+.
|
||||
|
||||
Version 2.0.31 (2012-2-27)
|
||||
============================
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
/*
|
||||
// define an overall custom text extraction function
|
||||
textExtraction: function(node) {
|
||||
textExtraction: function(node, table, cellIndex) {
|
||||
return $(node).text();
|
||||
}
|
||||
*/
|
||||
@ -33,12 +33,12 @@
|
||||
// In this example, textExtraction 1-5 functions don't really need to
|
||||
// be defined, since they can also be obtained using `$(node).text()`
|
||||
textExtraction: {
|
||||
0: function(node) { return $(node).find("strong").text(); },
|
||||
1: function(node) { return $(node).find("div").text(); },
|
||||
2: function(node) { return $(node).find("span").text(); },
|
||||
3: function(node) { return $(node).find("em").text(); },
|
||||
4: function(node) { return $(node).find("a").text(); },
|
||||
5: function(node) { return $(node).find("u").text(); }
|
||||
0: function(node, table, cellIndex){ return $(node).find("strong").text(); },
|
||||
1: function(node, table, cellIndex){ return $(node).find("div").text(); },
|
||||
2: function(node, table, cellIndex){ return $(node).find("span").text(); },
|
||||
3: function(node, table, cellIndex){ return $(node).find("em").text(); },
|
||||
4: function(node, table, cellIndex){ return $(node).find("a").text(); },
|
||||
5: function(node, table, cellIndex){ return $(node).find("u").text(); }
|
||||
}
|
||||
|
||||
});
|
||||
@ -60,6 +60,7 @@
|
||||
<ul>
|
||||
<li>The textExtraction function setting for each column was added in version 2.0.12 (not part of the original plugin).</li>
|
||||
<li>The "First Name" column is sorting by the contents of the <strong> tag (in red).</li>
|
||||
<li>Added "table" and "cellIndex" variables to the textExtraction function. <span class="tip"><em>New!</em></span> version 2.1.2.</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
|
@ -807,26 +807,25 @@
|
||||
<td>String Or Function</td>
|
||||
<td>"simple"</td>
|
||||
<td>Defines which method is used to extract data from a table cell for sorting.
|
||||
Built-in options include <code class="hilight">"simple"</code> and <code class="hilight">"complex"</code>. Use complex if you have data marked up
|
||||
inside of a table cell like: <code class="hilight"><td><strong><em>123 Main Street</em></strong></td></code>.
|
||||
The built-in option is <code class="hilight">"simple"</code> which is the equivalent of doing this inside of the textExtraction function: <code class="hilight">$(node).text();</code>.
|
||||
<div class="collapsible">
|
||||
<br>
|
||||
Complex can be slow in large tables so consider writing your own text extraction function "myTextExtraction" which you define like:
|
||||
<pre class="js">var myTextExtraction = function(node){
|
||||
You can customize the text extraction by writing your own text extraction function "myTextExtraction" which you define like:
|
||||
<pre class="js">var myTextExtraction = function(node, table, cellIndex){
|
||||
// extract data from markup and return it
|
||||
// originally: return node.childNodes[0].childNodes[0].innerHTML;
|
||||
return $(node).text();
|
||||
return $(node).find('selector').text();
|
||||
}
|
||||
$(function(){
|
||||
$("#myTable").tableSorter( { textExtraction: myTextExtraction } );
|
||||
});</pre>
|
||||
tablesorter will pass a jQuery object containing the contents of the current cell for you to parse and return. Thanks to Josh Nathanson for the examples. Updated to a jQuery example by Rob G (Mottie).<br>
|
||||
<br>
|
||||
Now if the text you are finding in the script above is say a number, then just include the <a href="#headers"><code class="hilight">headers</code></a> sorter option to specify how to sort it. Also in this example, we will specify that the special textExtraction code is only needed for the second column ("1" because we are using a zero-based index). All other columns will ignore this textExtraction function.
|
||||
tablesorter will pass the current table cell object for you to parse and return. Thanks to Josh Nathanson for the examples. Updated to a jQuery example by Rob G (Mottie).
|
||||
<p>Now if the text you are finding in the script above is say a number, then just include the <a href="#headers"><code class="hilight">headers</code></a> sorter option to specify how to sort it. Also in this example, we will specify that the special textExtraction code is only needed for the second column ("1" because we are using a zero-based index). All other columns will ignore this textExtraction function.</p>
|
||||
<p>Added <code class="hilight">table</code> and <code class="hilight">cellIndex</code> variables to the <code class="hilight">textExtraction</code> function in version 2.1.2.</p>
|
||||
<pre class="js">$(function(){
|
||||
$("table").tablesorter({
|
||||
textExtraction: {
|
||||
1: function(node) {
|
||||
1: function(node, table, cellIndex) {
|
||||
return $(node).find("span:last").text();
|
||||
}
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* TableSorter 2.1.1 - Client-side table sorting with ease!
|
||||
* TableSorter 2.1.2 - Client-side table sorting with ease!
|
||||
* @requires jQuery v1.2.3
|
||||
*
|
||||
* Copyright (c) 2007 Christian Bach
|
||||
@ -87,9 +87,9 @@
|
||||
}
|
||||
} else {
|
||||
if (typeof(te) === "function") {
|
||||
text = te(node);
|
||||
text = te(node, tbl, cellIndex);
|
||||
} else if (typeof(te) === "object" && te.hasOwnProperty(cellIndex)){
|
||||
text = te[cellIndex](node);
|
||||
text = te[cellIndex](node, tbl, cellIndex);
|
||||
} else {
|
||||
text = $(node).text();
|
||||
}
|
||||
@ -199,7 +199,7 @@
|
||||
for (j = 0; j < totalCells; ++j) {
|
||||
t = trimAndGetNodeText(table.config, c[0].cells[j], j);
|
||||
// don't bother parsing if the string is empty - previously parsing would change it to zero
|
||||
cols.push( t === '' ? '' : parsers[j].format(t, table, c[0].cells[j], j));
|
||||
cols.push( parsers[j].format(t, table, c[0].cells[j], j) );
|
||||
}
|
||||
cols.push(cache.normalized.length); // add position for rowCache
|
||||
cache.normalized.push(cols);
|
||||
|
4
js/jquery.tablesorter.min.js
vendored
4
js/jquery.tablesorter.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tablesorter",
|
||||
"version": "2.1.1",
|
||||
"version": "2.1.2",
|
||||
"title": "tablesorter",
|
||||
"author": {
|
||||
"name": "Christian Bach",
|
||||
|
Loading…
Reference in New Issue
Block a user