Display a selected row on open?

Display a selected row on open?

matolamatola Posts: 23Questions: 6Answers: 1

Do you know if there is a way to pass a Row_Id to DataTables at initializing, so that the table opens on the correct page with that specific row highlighted?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin

    There is no built in option for that in DataTables. You would need to use the API. The page.jumpToData() plug-in might be of particular interest.

    Allan

  • matolamatola Posts: 23Questions: 6Answers: 1

    Thank you. Tried it, but get "Uncaught TypeError: Cannot read property 'jumpToData' of undefined".

    Debug code: ulutog

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin

    I'd need a link to the page to be able to see how the plug-in is being loaded and used. For example you need to use $().DataTable() to use that plug-in (not $().dataTable()).

    Allan

  • matolamatola Posts: 23Questions: 6Answers: 1

    The page is on my local production server which is protected from the internet.
    And I am afraid I am lost about the "dataTable" and "DataTable" issue. I simply placed that code below efter the initialization of dataTable():

    $.fn.dataTable.Api.register( 'page.jumpToData()', function ( data, column ) {
        var pos = this.column(column, {order:'current'}).data().indexOf( data );
     
        if ( pos >= 0 ) {
            var page = Math.floor( pos / this.page.info().length );
            this.page( page ).draw( false );
        }
     
        return this;
    } );
    
  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    Answer ✓

    I'd need a link to the page to be able to offer any help as I'm really just guessing at the moment. Use $().DataTable() and not $().dataTable() to create the table is my best guess without a link to the page.

This discussion has been closed.