Datatables Warning(table id = 'example'): cannot reinitialise data table

Asked

Viewed 202 times

0

I am working with an example of datatable rowgroup and getting an error like this when loading the page:

Datatables Warning(table id = 'example'): cannot reinitialise data table ##

<script type="text/javascript" language="javascript">
        $(document).ready(function() {
            $('#example').DataTable({
                "processing": true,
                "serverSide": true,
                "ajax": {
                    "url": "tableProcessa.php",
                    "type": "POST"
                }
            });
        });
        
    </script>

    <script type="text/javascript" language="javascript">
        $(document).ready(function() {
            $('#example').DataTable({
                order: [
                    [0, 'asc']
                ],
                rowGroup: {
                    dataSrc: 0
                }
            });
        });
        
    </script>
<table width="100%" class="display" id="example" cellspacing="0">
        <thead>
            <tr>
                <th>OP</th>
                <th>Nome</th>
                <th>Cliente</th>
                <th>Trabalho</th>
                <th>Data</th>
                <th>Obs</th>
            </tr>
        </thead>
</table>

  • You can’t start datatables twice. I don’t understand why you’re doing this in the same ready event, though in separate blocks. Kind of pointless that.

  • Because you don’t put the two together $('#example').DataTable({ in one?

1 answer

0


The log itself is displaying the error "cannot reinitialise data table", that is, you cannot reboot the DataTable. Start only once and make all necessary settings as in the following example.

<script type="text/javascript" language="javascript">
$(document).ready(function() {
    $('#example').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: "tableProcessa.php",
            type: "POST"
        },
        order: [
            [0, 'asc']
        ],
        rowGroup: {
            dataSrc: 0
        }
    });
});
</script>
  • Thanks! I managed to solve my problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.