i am Django user i want to render out my api data using jQuery. Api data is rendered but the datatable is not working properly. but when i render data in datatable using django template datatable working fine. i thing some class's of datatable maybe not working. i try harder but i don't know how can i debug this thing. can anybody know how can i render datatable properly in html using jQuery?
<table id="approvedData">
<thead>
<tr>
<th>ID</th>
<th>Story</th>
<th>Created By</th>
<th>Timestamp</th>
<th>Priority</th>
<th>Action</th>
</tr>
</thead>
<tbody id="approvedList">
</tbody>
</table>
index.js
function fetchData() {
$.ajax({
type: 'GET',
url: endpoint,
success: function (data) {
console.log(data)
var html = '';
data.map(object => {
let storyStatus = ('Story not finish');
let colorClassName = ("badge-danger");
if (object.story_status === "sf") {
colorClassName = "badge-success";
storyStatus = "Story finish"
}
if (object.story_status === "fr") {
colorClassName = "badge-success";
storyStatus = "Approved"
}
html += `<tr>
<td> ` + object.id + `</td>
<td><a href="#"> ` + object.title + `</a></td>
<td> ` + object.author + `</td>
<td> ` + moment(object.created_on).fromNow() + `</td>
<td><span class="badge ${colorClassName} id="story-status">${storyStatus}</span></td>
<td>
<div class="table-btns">
<a href="${updateURL}update/${object.id}" class="table-btn table-btn--edit">
<i class="icon ion-ios-create"></i>
</a>
<a href="#" class="table-btn table-btn--delete">
<i class="icon ion-ios-trash"></i>
</a>
</div>
</td>
</tr>`;
//This is selector of my <tbody> in my table
$("#approvedList").html(html);
$('.table-btn--delete').click(function () {
var this_html = $(this);
var pk = this_html.parent().parent().parent().children().first().text();
swal({
title: "Are you sure?",
text: "You will not be able to recover this story!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
$.ajax({
url: '{% url "del" %}',
type: 'POST',
headers: { "X-CSRFToken": '{{csrf_token}}' },
data: { pk: pk },
success: function () {
swal("Story has been deleted!", {
icon: "success",
});
this_html.parent().parent().parent().remove();
}
});
} else {
swal("Story is safe");
}
});
});
});
}
});
};
fetchData();
setInterval(fetchData, 2000)