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)
Jamaur
Posts: 87Questions: 10Answers: 0
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.
This discussion has been closed.
Replies
...
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
Thanks for replying. Is there any way of distinguishing the second draw event from the first?
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 theinit
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