I want to use DataTables however I can't seem to get it working.
I want to use DataTables however I can't seem to get it working.
Any thoughts as to why I am getting an empty 12 row table ?
Link to test case:
Debugger code (debug.datatables.net): orayug
Error messages shown: DataTables warning: table id=auditChecksList - Requested unknown parameter '0' for row 0, column 0.
For more information about this error, please see http://datatables.net/tn/4
Description of problem: there are 12 rows in total and the grid actually creates 12 empty rows
-- my sample data, there are 12 rows in total and the grid actually creates 12 empty rows
-- url : https://localhost:44336/[REMOVED]/Overview?handler=AuditComplete
[
{"Id":12,"RequestedByAuditor":"Dev Gebruiker 01","CreatedOn":"2020-07-13","DeadlineDateTime":"2020-07-31T00:00:00","CompletedByAuditor":"Dev Gebruiker 01"}
,{"Id":18,"RequestedByAuditor":"Dev Gebruiker 01","CreatedOn":"2020-07-16","DeadlineDateTime":"2020-07-31T00:00:00","CompletedByAuditor":"Dev Gebruiker 01"}
,{"Id":19,"RequestedByAuditor":"Dev Gebruiker 01","CreatedOn":"2020-07-17","DeadlineDateTime":"2020-07-31T00:00:00","CompletedByAuditor":"Dev Gebruiker 01"}, ...rest removed [12 in total].
]
-- Razor Page : Overview.cshtml
public IActionResult OnGetAuditComplete()
{
List<AuditCompleteDTO> auditDtoList = new List<AuditCompleteDTO>();
auditDtoList = _integrityCheckService.GetChecksForAuditTeam(UserUniqueIdentifier); // returns List<AuditCompleteDTO>
return new JsonResult(auditDtoList);
}
-- Razor Page Html : Overview
Id | CompletedByAuditor | CreatedOn | DeadlineDateTime | RequestedByAuditor |
---|
-- Javascript
$(document).ready(function () { $('#auditChecksList').DataTable({ ajax: { url: "?handler=AuditComplete", dataSrc: '' }, columns: [ { data: 'Id' }, { data: 'RequestedByAuditor' }, { data: 'CreatedOn' }, { data: 'DeadlineDateTime' }, { data: 'CompletedByAuditor' } ] }); });
Answers
Have you follow the steps in the technical notes linked to in the error? That'll be the place to start,
Colin
The technical notes were woefully ill equipped to assist me. I have however resolved my issue through time consuming trial and error.
Explaining your error may help others.
my type had properties such as Id, CreatedOn, RequestedByAuditor...etc and failed
my columns definition would work with camelcase: id, createdOn, requestedByAuditor..etc
So just to confirm, the issue was a case error in the
columns.data
values you were using? I'll add "Check the parameter name letter cases" into the document if so (then hopefully it won't be woeful!).Allan