i using Jquery Data Table for show my data.according this question Trying to show extra information in a responsive DataTable i want to show extra information within a Responsive DataTable.but there is a different with this question that my extra information must be called from ajax.i wrote this codes:
let table = $('#data-table-order').DataTable({
"responsive": {
"details": {
"renderer":async function (api, rowIdx, columns) {
// Show hidden columns in row details
var data = $.map(columns, function (col, i) {
return col.hidden
? '<tr><td>' + col.title + ':</td> ' +
'<td>' + col.data + '</td></tr>'
: '';
}).join('');
await format(api.row(rowIdx).data(),'mobile').then(
u=>
{
data += u;
data = $('<table width="100%"/>').append( data ).prop('outerHTML');
return data;
});
}
}
}
});
my extra information are in format function:
function format(d, type) {
return new Promise((resolve, reject) => {
let postData = "XXXXorderID=" + d[0] + "&type=" + type
$.ajax({
url: 'XXXX',
type: 'POST',
data: postData,
success: function (response) {
resolve(response);
},
error: function (data) {
reject(new Error('Whoops'))
}
})
});
Edit:u
is a output of a procedure of sql that contains <tr><td>...</td></tr>
. this procedure runs by my ajax code in format function.u
is a string response of my Ajax.
but don't show any data in output.
EDIT2:
i try add async
to format function(d, type) {
:
async function format(d, type) {.....
but it didn't work.