Unable to display data in data table

Unable to display data in data table

sunsetsunset Posts: 1Questions: 1Answers: 0

Link to test case: https://localhost:44329/DocList
Debugger code (debug.datatables.net): imizoz
Error messages shown: DataTables warning: table id=DT_Load - Requested unknown parameter 'DocId' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
Description of problem: Unable to pull data from SQL server into the data table, although the data can be displayed correctly in a plain HTML table.

Source file 1). index.cshtml:

@* FileType
DocId ClientNumber FileSection DocType Description RefDescription Year PeriodEnd DocDate LastAccessedDate

@section Scripts{

Source file 2). DocList.js:

var dataTable;

$(document).ready(function () {
loadDataTable();
});

function loadDataTable() {
dataTable = $('#DT_load').DataTable({
"ajax": {
"url": "/api/doc",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "DocId", "width": "10%" },
{ "data": "ClientNumber", "width": "10%" },
{ "data": "FileSection", "width": "10%" },
{ "data": "DocType", "width": "10%" },
{ "data": "Description", "width": "10%" },
{ "data": "RefDescription", "width": "10%" },
{ "data": "Year", "width": "10%" },
{ "data": "PeriodEnd", "width": "10%" },
{ "data": "DocDate", "width": "10%" },
{ "data": "LastAccessedDate", "width": "10%" }
//{ "data": "FileType", "width": "8%" },
],
"language": {
"emptyTable": "no data found"
},
"width": "100%"
});
}

Source file 3). Doc.cs:

namespace DocRetention.Model
{
public class Doc
{
[Key]
public string DocId { get; set; }

    [Required]
    public string ClientNumber { get; set; }
    public string FileSection { get; set; }
    public string DocType { get; set; }
    public string Description { get; set; }
    public string RefDescription { get; set; }
    public string Year { get; set; }
    public string PeriodEnd { get; set; }
    public string DocDate { get; set; }
    public string LastAccessedDate { get; set; }
    public string FileType { get; set; }
}

}

Answers

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    Unfortunately we can't access your test case with localhost.

    Did you follow the troubleshooting steps in the error's link?
    http://datatables.net/tn/4

    Basically your data structure doesn't match your Datatables config. You might need to use ajax.dataSrc if your data isn't in the data object. Or maybe you are returning arrays instead of objects in the Ajax response. If you still need help then please post the first few rows of the Ajax response using the browser's network inspector. This will allow us to see your data structure in order to offer suggestions.

    Kevin

This discussion has been closed.