I want to use name and id from data source in one column. .netcore, json
I want to use name and id from data source in one column. .netcore, json
I am new to using datatables and I would like to be able to access the id from my data source while editing the name column(line18),
I just need a link which uses the id whilst displaying the name. The table works perfectly fine, im just not sure how to access the other data items.
Here is my js file:
var dataTable;
$(document).ready(function () {
loadDataTable();
});
function loadDataTable() {
dataTable = $('#tblData').DataTable({
"ajax": {
"url": "/admin/city/GetAll",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "name",
"render": function (data) {
//here is where I want to be able to use id and name from data source:
return`<div><a asp-action="Details" asp-controller="Admin" asp-route-id="${data.id}">${data}</a></div>`
}, "width": "40%" },
{
"data": "id",
"render": function (data) {
return `<div class="text-center">
<a onclick=Delete("/Admin/city/Delete/${data}") class='btn btn-danger text-white' style='cursor:pointer; width:100px;'>
<i class='far fa-trash-alt'></i>Delete
</a>
</div>
`;
}, "width": "20%"
}
],
"language": {
"emptyTable": "No Records Found"
},
"width": "100%"
});
any help or a point in the right direction would be really helpful
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
This question has an accepted answers - jump to answer
Answers
The third parameter passed into the
columns.render
function is the full data object for the row. So you should be able to dorow.id
(if you add the third parameter to your function).Allan
Perfect thank you!