1

I am using jQuery DataTables to display a paginated table. I now want to jump to the page that contains a certain row (with the current filter/sort settings). If I know the index of the row I can easily do this with something like tbl.fnPageChange( Math.floor(rowi / tbl.fnSettings()._iDisplayLength) );.

However, I only know the index of the data object in the data array (as returned by tbl.fnGetData()).

Is there a simple way to get the row index based on this data index? So pretty much the opposite of fnGetPosition()?

3
  • datatables.net/reference/api/row().index() doesn't do what you're looking for? Commented Mar 11, 2015 at 0:08
  • @Nils, did you figure this out? Commented Mar 30, 2015 at 13:14
  • @Margo, Yeah, just posted an answer with my 'solution'. It's pretty hacky though :) Commented Apr 3, 2015 at 13:09

1 Answer 1

1

Update: I hacked something together based on looping through the aiDisplay array:

function find_display_index(dataTable, data_index) {
    var oSettings = dataTable.fnSettings();
    var row_index = -1;
    for(var j = 0; j < oSettings.aiDisplay.length; j++) {
        if(oSettings.aiDisplay[j] == data_index) {
            row_index = j;
            break;
        }
    }
    return row_index;
}

Not sure if this is the best (or even totally correct) way, but it seems to work!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.