Can't select another row after ajax.reload
Can't select another row after ajax.reload
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",
                This question has an accepted answers - jump to answer
Answers
It looks like I'm hitting this functionality: https://datatables.net/extensions/select/examples/initialisation/reload.html (Retain selection on reload) but in my case it is undesirable. How do I turn in off?
I also need those rowId's for another functonality.
Found out that if I call
testTable.row({selected: true}).deselect();
before calling ajax.reload(), it seem to work...
Is this correct solution?
Yes - the row selection reselection after a reload cannot currently be turned off using an option flag.
Allan