Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81934

Can't select another row after ajax.reload

$
0
0

Hi.
Using datatables with serverSide.
I need to refresh current page, reading data from backend, and select specific row.

    var globalRowSelector = null;
    var testTable = $testtable.DataTable({
            serverSide : true,
            select : {style : 'single'},
            ajax: ...,
            columns: ...,
            drawCallback : function() {
                console.log("on drawCallback");

                var api = this.api();
                // select row by globalRowSelector or first row
                api.row(globalRowSelector != null ? globalRowSelector : 0).select();
            }
    });

    testTable.on("select", function() {
            console.log("on table select");
    });

    $("#testbtn1").click(function(e) {
            globalRowSelector = 2; // need to select third row after page refresh
            testTable.ajax.reload(null, false);
    })

On button click I see data on page refreshed, the third row gets selected for a moment and then "on table select" fires again and selects row number 0 again. I can't prevent this from happening.
Or if I select another row manually and hit the button, again row number 2 gets selected for a moment and then selection gets back to previously selected row.
Why does this happen? How can I programmatically select a specific row after page refresh?

"datatables.net": "^1.10.16",
"datatables.net-bs": "^2.1.1",
"datatables.net-select-bs": "^1.2.3",

Viewing all articles
Browse latest Browse all 81934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>