ajax.reload() and .row().show()

ajax.reload() and .row().show()

agiorgagiorg Posts: 3Questions: 0Answers: 0
edited October 2020 in Free community support

hello,
I have a perfectly working ajax datatable in which with an external button which adds a row after a further ajax post call.

when I call back from this ajax call, I have this:

success: function (response) {
                                table.ajax.reload();
                                highlightRow(response.id, table)
                            },

in which the highlightRow is the well known:

window.highlightRow = function(id, table) {
    var row = table.row(function ( idx, data, node ) {
        return data.id == id;
    } );
    if (row.length > 0) {
        row.select()
            .show()
            .draw(false);
    }
}

meant to be re-used in many parts.
Now my 2 questions:
1- after the table.ajax.reload the table in the browser is fine, there is the new record: but inside the highlightRow function this new record is missing, why?
2- the row.select().show().draw(false) works ONLY if I comment out the table.ajax.reload, why?

thanks a lot

Replies

  • agiorgagiorg Posts: 3Questions: 0Answers: 0

    obviously my target is: I have so many records, that when I asynchronously add a new row I want to jump there. Thanks again

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    Maybe use the callback parameter of the ajax.reload() API to call the function to show the row. With what you have you are calling the highlightRow function before the ajax.reload() response.

    Kevin

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited October 2020

    Or, if your response contains the newly inserted row data use row.add() to add the row and eliminate the ajax.reload(). row.add() returns an API instance of the new row that you can use for row().ahow(), etc.

    Kevin

  • agiorgagiorg Posts: 3Questions: 0Answers: 0

    thanks a lot kevin!

This discussion has been closed.