DataTables warning: table id=tblData - Requested unknown parameter 'id' for row 0, column 1
DataTables warning: table id=tblData - Requested unknown parameter 'id' for row 0, column 1
anujpratap3
Posts: 5Questions: 1Answers: 0
in DataTables
I am stuck with this issue from couple of days. Can someone help me please?
Category Model:
public class Category
{
[Key]
public int Id { get; set; }
[Required]
[Display(Name="Ennter category name")]
[MaxLength(100,ErrorMessage ="Category name cannot exceed 200 characters")]
public string Name { get; set; }
}
Controller:
public IActionResult GetAll()
{
var result = _db.Category.GetAll();
return Json(new { data = result });
}
Category.js:
var dataTable;
$(document).ready(function () {
loadDataTable();
});
function loadDataTable() {
dataTable = $("#tblData").DataTable({
'ajax': {
"url": "/Admin/Category/GetAll",
"type": "GET",
"dataType": "JSON"
},
"columns": [
{
"data": "name",
},
{
"data": "id",
"render": function (arg) {
return
`<div class="text-center">
<a href="/Admin/Category/Upsert/${arg}" class="btn btn-success text-white" style="cursor:pointer;">
<i class="fas fa-edit"></i>
</a>
<a class="btn btn-danger text-white" style="cursor:pointer;">
<i class="fas fa-trash-alt"></i>
</a>
</div>`;
}
}
]
});
}
I have no idea what is wrong with the code. In datatable name column is populating but other column with buttons are not populating and possibly throwing error.
Answers
Here is the html past:
You have
"data": "id"
which tells Datatables to look for anid
object in your row data. Do you have anid
object? If not you can use"data": null
.Kevin
Hi kthorngren, I have given the model please check above. Id column is present. I have debugged data is there both name and Id still it throws error.
You can check screen shot to see the data.
Hi, I have figured it out. Issue was because of the way I was creating html string in 2nd column 'render': function(){}. There I am returning html string inside tilde character so converted it into simple html string and working like usual. Thanks