Skip to content

Commit

Permalink
Add support to exclude rows
Browse files Browse the repository at this point in the history
  • Loading branch information
tristen committed Nov 6, 2012
1 parent 064ee61 commit 8965e59
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lint:
./node_modules/.bin/jshint tablesort.js

tablesort.min.js:
./node_modules/.bin/uglifyjs tablesort.js > tablesort.min.js

lint:
./node_modules/.bin/jshint tablesort.js
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ new Tablesort(document.getElementById('table-id'), {
});
```

__Exclude columns__
For columns that do not require sorting, you can add a class of `no-sort` to a columns `th` element.
__Exclude columns or rows__
For columns or rows that do not require sorting, you can add a class of `no-sort` to a columns `th` or a `tr` element.
``` html
<th class='no-sort'>Name</th>

<tr class='no-sort'>
<td>1</td>
<td>Gonzo the Great</td>
<td>12-2-70</td>
<td>Radishes</td>
<td>$0.63</td>
</tr>
```

__Refresh sort on appended data__
Expand Down
16 changes: 12 additions & 4 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,19 @@ <h3>Ascending/Descending</h3>
descending: true
});</pre>
<p class='notice'><strong>Note:</strong> If you are using the default CSS provided you'll need to reverse the class names that style the arrows.</p>
<h3>Exclude columns</h3>
For columns that do not require sorting, you can add a class of <code>no-sort</code> to a columns <code>th</code> element.
<pre class='prettyprint'>
&lt;th class='no-sort'&gt;Name&lt;/th&gt;</pre>
<h3>Exclude columns or rows</h3>
For columns or rows that do not require sorting, you can add a class of <code>no-sort</code> to a columns <code>th</code> or a <code>tr</code> element.
<pre class='prettyprint'>
&lt;th class='no-sort'&gt;Name&lt;/th&gt;

&lt;tr class='no-sort'&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Gonzo the Great&lt;/td&gt;
&lt;td&gt;12-2-70&lt;/td&gt;
&lt;td&gt;Radishes&lt;/td&gt;
&lt;td&gt;$0.63&lt;/td&gt;
&lt;/tr&gt;
</pre>
<h3 id='refresh'>Refresh sort on appended data</h3>
<p>Tablesort supports sorting when new data has been added. Simply call the refresh method.</p>
<pre class='prettyprint'>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tablesort",
"description": "A sorting component for HTML tables",
"version": "1.4.2",
"version": "1.5.0",
"author": "tristen <@fallsemo>",
"main": "./tablesort.js",
"ender": "./ender.js",
Expand Down
10 changes: 8 additions & 2 deletions tablesort.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// tablesort.js
// tristen @fallsemo
// Version: 1.5.0
// Author: tristen @fallsemo

(function () {
function Tablesort(el, options) {
el.tagName === 'TABLE' ? this.init(el, options || {}) : console.error('Element must be a table');
Expand Down Expand Up @@ -144,7 +146,11 @@

// append rows that already exist rather than creating new ones
for(i = 0; i < newRows.length; i++) {
t.tBodies[0].appendChild(newRows[i]);
// Don't sort on rows specified. TODO might want to
// do this more upstream.
if(!hasClass(newRows[i], 'no-sort')) {
t.tBodies[0].appendChild(newRows[i]);
}
}
},
refresh: function() {
Expand Down
5 changes: 3 additions & 2 deletions tablesort.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8965e59

Please sign in to comment.