Upon receiving data from the web server, I want to manipulate it in Datatable. However, the response data is encoded and requires decoding using an asynchronous function called decodeData(). I attempted to call this async function in the dataSrc section as shown below, but the table does not display the data.
$(document).ready(function () {
$('#example').DataTable({
processing: true,
serverSide: true,
"ajax": {
"url": "http://localhost:3000",
"dataSrc": async function ( json ) { // Added async
// Call the async function here
json.data = await decodeData(json)
return json.data;
}
});
});
I also tried using the xhr event, but encountered issues with its functionality.
var table = $('#example')
.on('xhr.dt', async function ( e, settings, json, xhr ) { //Added async
json = await decodeData(json);
} ).DataTable({
processing: true,
serverSide: true,
"ajax": {
"url": "http://localhost:3000",
},
});
It seems that Datatable event handlers do not support async functions, causing them to not wait for the Promise's completion. How can I ensure that the asynchronous function is called before the table is rendered?