Cannot reinitialise DataTable

Cannot reinitialise DataTable

MaheshicscomMaheshicscom Posts: 2Questions: 1Answers: 0
edited May 2020 in Free community support

This is my code:

$(document).ready(function () {
        var oTable = $('#example').DataTable({
            "ajax": {
                type: "POST",
                url: "UserRoleServlet",
                data: {SesCode: UsrSession, UserCode: UsrIdName, comid: UsrComId},
                dataSrc: ""
            },
            "columns": [
                {"data": "idIndex"},
                {"data": "NAME"},
                {
                    "data": null,
                    "mRender": function (data, type, full) {
                        return '<button onclick=loadEdit(' + (full.idIndex) + ')>Edit</button>';
                    }
                }
            ]
        });
    });
}

$(document).ready(function () {
    var table = $('#example').DataTable();
    $('#example tbody').on('click', 'tr', function () {
        var data = table.row(this).data();
        alert('You clicked on ' + data[0] + '\'s row');
    });
});

Error msg:
DataTables warning: table id=example - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

Help me to solve

Thanks

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • MaheshicscomMaheshicscom Posts: 2Questions: 1Answers: 0

    I need add click event to get cell data!

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Try removing lines 21-23 so there's just a single

    $(document).ready(function () {
    });
    

    block.

    Colin

This discussion has been closed.