Hi @paul.korver,
I tested adding a custom parser to AUI’s sortable table, and it works according to that plugin’s documentation.
Here is an example table with priorities in it:
<table id="custom-parser-example" class="aui aui-table-sortable">
<thead>
<tr>
<th class="aui-table-column-issue-key">Issue key</th>
<th class="sorter-priority">Priority</th>
<th>Last updated</th>
<th>Summary</th>
<tr>
</thead>
<tbody>
<tr>
<td>TEST-12</td>
<td>High</td>
<td><time datetime="2017-04-20T14:00:00Z">April 20, 2017</time></td>
<td>Table sorting should be allowed</td>
</tr>
<tr>
<td>WIN-87</td>
<td>Blocker</td>
<td><time datetime="2018-04-23T11:30:00Z">April 23, 2018</time></td>
<td>Issue Page doesn't load in IE</td>
</tr>
<tr>
<td>DRINK-7</td>
<td>Low</td>
<td><time datetime="2018-04-01T17:30:00Z">April 1, 2018</time></td>
<td>Vending Machine is empty</td>
</tr>
<tr>
<td>TEST-7</td>
<td>Medium</td>
<td><time datetime="2018-01-11T09:30:00Z">January 11, 2018</time></td>
<td>My hovercraft is full of eels</td>
</tr>
</tbody>
</table>
Note the CSS class sorter-priority
on the <th>
element – this is important. This indicates that a custom parser with an id of priority
should be used to sort the table.
Let’s create that parser:
(function() {
var priorityMap = {
'high': 3,
'blocker': 5,
'low': 1,
'medium': 2
};
AJS.$.tablesorter.addParser({
id: 'priority',
is: function(nodeValue, table, cell) {
return false;
},
format: function(nodeValue, table, cell) {
var raw = (nodeValue || '').toLowerCase().trim();
return priorityMap[raw] || -1;
},
type: 'numeric'
});
// Since we added a new sorter, but the table was added at page load,
// we'll need to kick off the sorting again.
AJS.$('#custom-parser-example').trigger('sort');
}());
Note that I have assigned numeric values to each priority; in this arrangement, “Medium” sorts above “Low”, which isn’t alphabetical order. This should do what you want.
So that others can discover this behaviour more readily, I will be adding this example to AUI’s documentation, along with a link to the version of the tablesorter plugin we’re using. Follow AUI-4755 for the status of that.
Cheers,
Daz