cannot read property 'length'

cannot read property 'length'

montoyammontoyam Posts: 568Questions: 136Answers: 5

I have looked at other posts on the forum but I don't see the resolution to my issue.

            var ToGenerateTable = $('#ToGenerate').DataTable({
                dom: 'frtip',
                ajax: 'api/ToGenerate',
                dataSrc: 'Table',
                idSrc: 'ImportID',
                columns: [
                    { data: "ImportID" },
                    { data: "DeptName" },
                    { data: "FTE" },
                    { data: "EmployeeCount" }
                ]
            })

json:

{"Table":[{"ImportID":121,"DeptName":"Ag Commissioner","FTE":48.15,"EmployeeCount":50},...

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921
    edited February 2020 Answer ✓

    Its possible the problem is that ajax.dataSrc needs to be within an object for the ajax option. Something like this:

    ajax: {
      url: 'api/ToGenerate',
      dataSrc: 'Table'
    },
    

    Also the idSrc: 'ImportID', is not correct. idSrc is an Editor option. You will want to use rowId in Datatables.

    Kevin

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    both those were exactly the issues:

                var ToGenerateTable = $('#ToGenerate').DataTable({
                    dom: 'frtip',
                    ajax: {
                        url: 'api/ToGenerate',
                        dataSrc: 'Table'
                    },
                    rowId: 'ImportID',
                    columns: [
                        { data: "ImportID" },
                        { data: "DeptName" },
                        { data: "FTE" },
                        { data: "EmployeeCount" }
                    ]
                })
    
    
This discussion has been closed.