Making the selected row visible

Making the selected row visible

galcottgalcott Posts: 53Questions: 15Answers: 1

I'm trying to do what should be a simple thing but haven't been able to find a way to make it work. After the user adds a new record to a table, I want to select that record and then make the record visible. The selection is no problem but I can't find a way to make the row visible. I'm not using pagination or the scroller extension. This is the code to do the selection. Is there a way to make the row visible after selecting it?

function SelectFormula (formulacode) {
  dtFormulas.ajax.reload(function() {
    dtFormulas.row( function ( idx, data, node ) { return data[0] === formulacode ? true : false; } ).select();
  });
}

This question has an accepted answers - jump to answer

Answers

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30

    Look into using page.jumpToData() plug-in.

    For example, include JS file for the page.jumpToData() plug-in and call the following method after the table data has been reloaded.

    dtFormulas.page.jumpToData(formulacode, 0);
    

    See more articles about jQuery DataTables on gyrocode.com and contact us if you need help with your project.

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    If you aren't using paging, do you mean you just want to scroll the document to that row?

    If so use row().node() to get the tr element in question and then scroll to it (either using a jQuery plug-in or your own position calculation, perhaps with jQuery's $().position() method).

    Allan

  • galcottgalcott Posts: 53Questions: 15Answers: 1

    Allan,

    Yes, I just want to scroll to that row. Can you give me some specific code for that? I'm far from an expert on this stuff! Thanks.

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin
    Answer ✓
    var pos = $(...).offset();
    $('body').scrollTop( pos.top );
    

    should do it. You'd need to fill in the jQuery selector for your row of course.

    Allan

    p.s. I should have said use $().offset(), not $().position() above. The code in this post is correct.

This discussion has been closed.