Bug: Table fires Draw x2 when in Client Mode and getting data from a data source (AJAX)

Bug: Table fires Draw x2 when in Client Mode and getting data from a data source (AJAX)

JamaurJamaur Posts: 87Questions: 10Answers: 0
edited August 2015 in Free community support

When the Datatable first loads, the Draw Event (not Callback) fires twice (x2).

  • The first, before data has loaded (before ajax)
  • The second, after data has loaded (after ajax)

This happens only when the table is in Client Mode (serverSide: false) & retrieving data from a data source:

var table = $('#example').DataTable( {
        "serverSide": false,
        "ajax": "https://api.myjson.com/bins/1frdi",
        "columns": [
            { "data": "name" },
            { "data": "position" },
            { "data": "office" },
            { "data": "extn" },
            { "data": "start_date" },
            { "data": "salary" }
        ]
    } );

The test case showing this issue: http://live.datatables.net/fitalevu/2/edit

The result is shown in the console. One can notice that the Draw event is being logged twice in the console.

Replies

  • JamaurJamaur Posts: 87Questions: 10Answers: 0

    ...

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin

    This is not a bug but intentional. The table has done a draw with the empty data that is available to it when initialised - therefore it should trigger the draw event. Then when the data has been loaded by Ajax it will do another draw, hence the second draw event.

    Allan

  • JamaurJamaur Posts: 87Questions: 10Answers: 0

    Thanks for replying. Is there any way of distinguishing the second draw event from the first?

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin

    You could attach your draw event in init (which will actually occur after the second as well, so you would need to execute whatever draw actions you need in the init event handler as well.

    There are probably other ways, but there isn't an externally accessible parameter that would given a simple draw count.

    Allan

This discussion has been closed.