Cannot select row on another page

Cannot select row on another page

jdoensjdoens Posts: 18Questions: 4Answers: 0
edited November 2017 in Free community support

Hi everyone,

I'm trying to select the row where I get a positive match but can't seem to gain focus of the row that I match. Below is my code
...
var dtable = $('#datatable').dataTable().api();

        dtable.rows().eq(0).each(function (index) {
            var row = dtable.row(index);
            var data = row.data();

            if (data.Name == 'John') {
                this.addClass("selected");
            }
        ...

I've also tried $(this).closest('tr').addClass('selected') and other variations but haven't had any luck. Any pointers would be greatly appreciated!

This question has an accepted answers - jump to answer

Answers

  • jdoensjdoens Posts: 18Questions: 4Answers: 0

    I answered my own question. I simply invoked the select() method by row.select().

  • jdoensjdoens Posts: 18Questions: 4Answers: 0

    So it works if the data is found on the first page, but the select doesn't happen if the data is on another page within the DataTable. Is this something I'm doing wrong?

  • jdoensjdoens Posts: 18Questions: 4Answers: 0

    row.show().draw(false) worked.

  • allanallan Posts: 48,430Questions: 1Answers: 7,007 Site admin

    There isn't a row.show() method in DataTables - I'm not entirely sure how that is working unless you have a plug-in method? Perhaps you can link to a page showing the issue?

    Allan

  • jdoensjdoens Posts: 18Questions: 4Answers: 0

    Sorry for the late reply. I am using a plugin for the show method. https://cdn.datatables.net/plug-ins/1.10.16/api/row().show().js

  • allanallan Posts: 48,430Questions: 1Answers: 7,007 Site admin
    Answer ✓

    Ah I see. Yes you would need to call draw() and pass false so it doesn't reset the paging.

    Allan

Sign In or Register to comment.