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.

Norman001Norman001 Posts: 3Questions: 1Answers: 0

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

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Have you follow the steps in the technical notes linked to in the error? That'll be the place to start,

    Colin

  • Norman001Norman001 Posts: 3Questions: 1Answers: 0

    The technical notes were woefully ill equipped to assist me. I have however resolved my issue through time consuming trial and error.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Explaining your error may help others.

  • Norman001Norman001 Posts: 3Questions: 1Answers: 0

    my type had properties such as Id, CreatedOn, RequestedByAuditor...etc and failed

    my columns definition would work with camelcase: id, createdOn, requestedByAuditor..etc

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin

    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

This discussion has been closed.