DataTables isn't loading data from controller

DataTables isn't loading data from controller

samwsamw Posts: 15Questions: 7Answers: 0
edited October 2023 in Free community support

The Datatable isn't loading/displaying data that I'm passing from my controller. I have a List of data in my controller (in .NET) which I'm sending to the html page as JSON but I receive this message in the browser when trying to load the datatable:
"DataTables warning: table id=tblCustomers - Requested unknown parameter 'CustomerID' for row 0, column 0"

Here's my code:

Controller:

HTML:

JS:

Answers

  • allanallan Posts: 62,992Questions: 1Answers: 10,367 Site admin

    Can you show me the JSON returned by the server please?

    "serverSide": true,

    Remove this. Your script does not implement server-side processing. You could implement that later if you have tens of thousands or more rows of data. Also it is actually nested in the ajax option, so it wouldn't do anything at the moment.

    Also, can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Allan

  • samwsamw Posts: 15Questions: 7Answers: 0

    I used the debugger and clicked upload. it said the data was sent to you.
    I removed "serverSide".

    using this js code above how do I see the json data being returned, which parameter do I use? It looks like I'm receiving 3 records.

  • allanallan Posts: 62,992Questions: 1Answers: 10,367 Site admin

    I used the debugger and clicked upload. it said the data was sent to you.

    I need the debug code please. It should give you a 6 character code.

    using this js code above how do I see the json data being returned, which parameter do I use

    Follow the instructions here to see the response from the server.

    Allan

  • samwsamw Posts: 15Questions: 7Answers: 0

    thank you for those instructions. It helped me find the problem:
    when the data returned as json to the html page it changed the columns names to camel case.
    here's the json data returned:
    [{"customerID":101,"customerName":"John Smith","customerState":"NY"},{"customerID":102,"customerName":"Edward Johnson","customerState":"RI"},{"customerID":103,"customerName":"Mary Jane","customerState":"VT"}]

    I changed the column names to use camel case and the data loaded successfully:
    "columns": [
    { data: "customerID" },
    { data: "customerName" },
    { data: "customerState" }
    // Add more columns as needed
    ]

  • allanallan Posts: 62,992Questions: 1Answers: 10,367 Site admin

    Good to hear. .NET's JSON seraliser does have an option to stop it changing case like that, but good to know you've got it running now.

    Allan

Sign In or Register to comment.