select row by id

select row by id

leodmleodm Posts: 4Questions: 2Answers: 0

Hi, I have static html tables turn to normal Datatables. Adding id to <tr> then I can´t access to given id, for example:

<table id="example"> ... <tr id="row-3"><td></td></tr> ... </table> <script> var example = $('#example').DataTable(); </script>
then I can´t access to row by id like the example here: https://datatables.net/reference/type/row-selector

var row = example.row('#row-3');

give an error "example.row is not a function"

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Can you link to a page showing the issue please? I don't immediately see what would be wrong there. You are using $().DataTable() which is correct - it would have guessed you were using $().dataTable() which would have resulted in that error, but your code above shows you aren't!

    Allan

  • leodmleodm Posts: 4Questions: 2Answers: 0

    Allan, After many hours of testing in chrome console, I realize that maybe the problem is that when using HTML (DOM) sourced data, I'm using this code for initialization:

    $(document).ready(function () { $('#cities').DataTable() }

    The document ready function is the problem,when I remove it I can access inmidiatly to all the datatables api!

    Can you confirm is that is maybe an issue?

    thnks in advance!
    LDM

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Not really I'm afraid. I'm not aware of any issue with using that method.

    Here is a little example which shows the API being accessed inside the document ready function.

    Allan

This discussion has been closed.