How to reach data column value in JSON format . I used row[requestStatus.name]
How to reach data column value in JSON format . I used row[requestStatus.name]
MesutDtk
Posts: 1Questions: 0Answers: 0
var dataTable;
$(document).ready(function () {
dataTable = $('#DT_RequestsAdmin').DataTable({
"ajax": {
"url": "/api/AdminRequest",
"type": "GET",
"datatype": "json"
},
autoWidth: false,
"columns": [
{ "data": "requestID", "width": "1%" },
{ "data": "summary", "width": "10%" },
{ "data": "description", "width": "15%" },
{ "data": "requesterUser.fullName", "width": "4%" },
{ "data": "engineerUser.fullName", "width": "4%" },
{ "data": "requestStatus.name", "width": "8%" },
{ "data": "department.name", "width": "7%" },
{ "data": "reason.name", "width": "10%" },
{
"data": "requestID",
"render": function (data, row) {
if (row['requestStatus.name'] == 'On Hold') {
return `<div class="w-75 btn-group" >
<a href="/Admin/Requests/upsert?id=${data}" class="btn btn-success text-white mx-2">
<i class="bi bi-pencil-square"></i></a>
</div>`
}
if (row['requestStatus.name'] == 'Canceled') {
return `<div class="w-75 btn-group" >
<a href="/Admin/Requests/upsert?id=${data}" class="btn btn-success text-white mx-2">
<i class="bi bi-pencil-square"></i></a>
<a onClick=Delete('/api/AdminRequest/'+${data}) class="btn btn-danger text-white mx-2">
<i class="bi bi-trash-fill" ></i></a>
</div>`
}
},
"width": "1%"
}
],
});
});
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
Replies
Are you asking about how to use the button click events? If so you should use delegated events like this example. If this doesn't help please provide a test case showing the issue along with more details of your questions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin