Requested unknown parameter

Requested unknown parameter

robsiarobsia Posts: 5Questions: 1Answers: 0

Can you help me understand why this error comes up?
DataTables warning: table id=list - Requested unknown parameter 'date' for row 0, column 1.

   "columns": [

        {
        "className":      'details-control',
        "orderable":      false,
        "data":           null,
        "defaultContent": '+'
        },  

        {"data": "date"},                              
        {"data": "name"},
        {"data": "lastname"},               
        {"data": "email"},                                              

    ],

The html is also correct. The json response does not give any error. I don't understand this.

Answers

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

    Did you follow the troubleshooting steps at the link provided in the error?
    https://datatables.net/manual/tech-notes/4

    Sounds like the JSON data structure doesn't match what Datatables expects as described in the Ajax doc.

    What is in the JSON response?

    Kevin

  • robsiarobsia Posts: 5Questions: 1Answers: 0

    I did not get an erro for json. Here is the json (with a length of 1 in the query)

    {"draw":1,"recordsTotal":"20554","recordsFiltered":"20554","data":"[{\"date\":\"2020-02-18 18:46:34\",\"name\":\"Bueno Balboa\",\"lastname\":\"\",\"email\":\"xxxxxxxx@gemai.com\"}]"}

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

    Looks like the correct structure except that the data object looks to be encapsulated into a JSON string twice:

    "data":"[{\"date\":\"2020-02-18 18:46:34\",\"name\":\"Bueno Balboa\",\"lastname\":\"\",\"email\":\"xxxxxxxx@gemai.com\"}]"
    

    Note the \ escaping the ". My guess is your server script is encapsulating the data it collected, ie, [{\"date\":\"2020-02-18 18:46:34\",\"name\":\"Bueno Balboa\",\"lastname\":\"\",\"email\":\"xxxxxxxx@gemai.com\"}] then doing another JSON encapsulation when returning the full response.

    Kevin

  • robsiarobsia Posts: 5Questions: 1Answers: 0

    No this is not a problem. It's something in datatables script .I need to get why it is returning this error. As you see "date" is there, but for some reasons is telling that it is "unknown"

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

    You are correct, the date is there. As I explained the problem is the data object has been JSON encapsulated twice so when Datatables parses the data object it is still a string causing the error. Let me dome for you.

    I took your data and columns definition and used it in this example:
    http://live.datatables.net/bilareco/1

    Using data to provide the data to Datatables. The same alert message is displayed. You can click the Edit in JS Bin button to see the code.

    Took the same code and use JSON.parse() on the data and now it works. Here is the updated example:
    http://live.datatables.net/bilareco/1

    What are you using for your server script?

    Kevin

  • robsiarobsia Posts: 5Questions: 1Answers: 0

    I'm using php on the server and the same output works on another project. What do you mean with encapsulated twice ? I see only an array [], that's not "normally" a problem.

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited February 2020

    Sorry, I provided the wrong link for the second example:
    http://live.datatables.net/yeyatato/1/edit

    What do you mean with encapsulated twice ? I see only an array []

    The " in front of the [ makes the data object a string not an array:

    "data":"[{\"date\":....
           ^
    

    When data is JSON encapsulated quotes (") are used to wrap the text. If that data is JSON encapsulated a second time all the quotes in the original are escaped with backslashes.

    I'm using php on the server and the same output works on another project.

    Is it one of the Datatables provided scripts or your own?

    Kevin

  • robsiarobsia Posts: 5Questions: 1Answers: 0

    Thank you! I didn't see it :smile:
    Solved!!

This discussion has been closed.