Mottie/tablesorter — pull request #192 by emmerich (2012-12-12 15:25:42+00:00)
Title: Ability to sort between tbodies

Recently, I've found the need in an application to sort between tbodies.

At present, tablesorter supports sorting within multiple tbodies, but does not support sorting the tbodies themselves.

tbody is described by the W3 standard as being a "represent[ation of] a block of rows that consist of a body of data" (http://www.w3.org/TR/html-markup/tbody.html). When sorting tables, I believe it could be a common use case to want to sort those bodies of data.

I've developed a patch for tablesorter that makes this possible and I believe is backwards compatible with the current tablesorter implementation.

### Sorting between tbodies
To tell tablesorter we want to be even considering sorting tbodies, we pass in the `sortBodies` flag in the options:

```javascript
$('table').tablesorter({
sortBodies: true
});
```

We also need to tell tablesorter how to obtain the "primary row" for each body. A body could have many rows, and tablesorter needs one row to extract the data from:

```javascript
$('table').tablesorter({
sortBodies: true,
primaryRow: function(body) {
// return the first row of the body
return $(body).find('tr').eq(0);
}
});
```

Running tablesorter like this will sort both between bodies and within them: the individual rows will be sorted against other rows in that body, and the bodies will be sorted against the primary rows of other bodies. See `examples/example-multibody-within.html`.

### Sorting between bodies whilst rows remain static
However, it's probably more common to want to keep the tbodies themselves sorted, but sort between them. So the individual rows will remain static relative to one another, but the bodies will move around. This is done using the current `infoBlock` class defined in tablesorter.

Putting an `infoBlock` class on a `tbody` whilst `sortBodies` is set to true, will cause tablesorter to ignore sorting the individual rows inside that body, and only sort the bodies themselves. See `examples/example-multibody.html`.

I'm quite new to tablesorter and how it works - so I've only managed to test my patch on the examples already in the repository. I'd appreciate if someone could take a look at my implementation and give some hints and hopefully we can get this pulled in.

Cheers