Get index of sorted row?
<p>In the context of <a href="https://datatables.net/" rel="nofollow">DataTables</a>, how do I get the index of a sorted row? </p>

<p>I have a paginated, sortable, filterable table where column <code>4</code> (i.e. the 5th column) contains a message number. I'm writing a function which switches the current page to the one displaying that message number, and highlights the row containing that entry. It looks like this:</p>

<pre><code>var currentHighlight = null;

function goToMessageNumber(number) {
  var table = $('#messages').DataTable();

  // remove current highlight
  if (currentHighlight) {
    $(table.row(currentHighlight).nodes()).removeClass('highlight');
  }

  // find the row we need
  var index = table.column(4).data().indexOf(''+number);
  if (index === -1) {
    return;
  }

  currentHighlight = index;

  // add new highlight
  $(table.row(currentHighlight).nodes()).addClass('highlight');

  // go to page
  var page = Math.floor(currentHighlight / table.page.len());
  table.page(page).draw(false);
}
</code></pre>

<p>It works perfectly if the table is in the initial sort order. However, this fails when filters or sorting is applied. What's the easy solution here?</p>