Я могу дать вам базовую демонстрацию того, как добавлять любую информацию или данные в Datatable с помощью Ajax.Я надеюсь, что вы получите представление об этом.Итак, вот мой HTML-код.
<div class="container">
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>img</th>
<th>Name</th>
<th>Lastname</th>
<th>Email id</th>
<th>Password</th>
<th>Birthdate</th>
<th>Zipcode</th>
<th>Phone Number</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
Итак, в моем HTML-файле я назначил 7 столбцов в таблицу данных, и мое тело пусто, потому что нам нужно динамически добавлять данные в столбец.
Здесьмой код Javascript.
$.ajax({
type: 'GET',
url: 'http://localhost:8080/gettable',
dataType: 'json',
contentType:'application/JSON'
})
.done(function(res){
console.log('Get Response:',res);
var table = $('#example').DataTable();
$.fn.dataTable.ext.errMode = 'none';
$.each(res.docs, function(index, user){
$.each(user, function(index2, sub_user){
$("#example").append($('<tr>')
.append($('<td>').append("Color name or anything"))
.append($('<td>').append("Color name or anything"))
.append($('<td>').append("Color name or anything"))
.append($('<td>').append("Color name or anything"))
.append($('<td>').append("Color name or anything"))
.append($('<td>').append("Color name or anything"))
.append($('<td>').append("Color name or anything"))
);
});
})
.fail(function(jqXHR, textStatus, err){
console.log('Ajax repsponse:',textStatus);
alert("nayy")
});
});
Итак, чтобы добавить что-либо в столбец, нам нужно использовать команду .append, которая добавит данные в ваш столбец.Я надеюсь, что это будет работать для вас.Спасибо.