Persistent Error: Requested unknown parameter '0' for row '0' column '0'
Persistent Error: Requested unknown parameter '0' for row '0' column '0'
I posted this question also on StackOverflow. I have tried my hardest to make use of datatables for the project.. but it just won't work. I've read all guides concerning flat Json formats
and I've troubleshoot it myself. Now, I can only humbly ask for help as to what is causing this error.. since I've encountered it BEFORE and I only had to add "dataSrc='' " to fix it..
What seems to be the problem? what is the error? how can I avoid this in the future?
This question has an accepted answers - jump to answer
Answers
Additional info: in truth there are more than that 1 column for JSON, html and the Jquery I displayed. I reduced it to that to see if it was formatting error.
Your SO question contains more information that this post, and from the code and information there, it appears that it should work.
Could you run the debugger or link to the page please? That will hopefully give me enough information to understand why it isn't working.
Allan
my sincere thanks allan for taking notice of this problem
some additional info:
-the page is structured in a way that makes use of a masterpage where all js and css are loaded.
-The site where the JSOn is being loaded is a .aspx file which gets it's JSON string from Newtonsoft JSON
I will also try this debugger and see why it does not output.. please keep me company a while longer sir Allan
I ran the debugger in google chrome by running the page, copying and pasting the code on the console part of inspect, it ran and then gave me this
Thank you very much for the help..
here is another debugger results. I fixed my error with the
setInterval
(I wanted my datatables to refresh every 10 seconds in case there are new records) The datatable refreshes properly now, but still, the error persistsThe JSON data returned is not correct. This is the first 3 records returned:
You have defined your columns to use objects:
The return JSON needs to be in a
data
object and should look more like this:You can see an example of this by looking at the AJAX tab of this page:
https://datatables.net/examples/ajax/objects.html
Kevin
Thanks Kevin for the response, but I have to make use of the Flat format.. this is the JSON the .aspx url is leaving.. It was also mentioned in the docs here that the flat file format is accepted.
that is also why I included
dataSrc =""
.is tehre a way to solve this?
Reason why I cannot change the source JSON: this is what the team is using, and said JSON will always be produced in this format..
Is there another approach I can use that uses the FLAT json format? like push and such? Please I just need a sample that works...
Yes, you are right about loading the flat file. I compared your debug to that of the flat data source example:
https://datatables.net/examples/ajax/custom_data_flat.html
One difference I see is the example has both
responseText
andresponseJSON
objects in thejqXHR
object. You can see the debug output of the example here. This can be seen in the debugger output underFull table state
. I tried your config and data (in a text file) on my system and it works and I also see theresponseJSON
object.Someone else can confirm but it seems the lack of having the
responseJSON
object might be causing the issue.Kevin
thank you Kevin. So how do I add said responseJSON to my code? what do I need to do basically?
IT WORKS NOW, DAMN!
I switched
columns: data
foraoColumns: mData
I also added
mDataProp:""
alongsidedataSrc: ""
WHY? WHY IS IT LIKE THIS? WHY IS
data
DIFFERENT FROMmData
?WHY
aoColumns
INSTEAD OFcolumns
?..still, phenomenal work with the plugin. Thank you very much @allan and @kthorngren
I'm not familiar with aspx but you probably need to set the response content type, in the aspx script, to something like
"application/json; charset=utf-8"
to allow it to return a json header.I believe, by default, Datatables sets the dataType to json in the ajax request and will expect the response to contain the json header.
Kevin
New problem though, buttons will not appear.
I did it like this :
`var tbl = $('#tblUserAccountsManagement').DataTable({
What could be the problem? Here is the debugger
Also yes @kthorngren I did set the response type to
"application/json; charset=utf-8"
Do none appear or does the Copy button appear?
If only the Copy then you probably will need to load the additional JS files for the other buttons as shown here:
https://datatables.net/download/release#Buttons
There was a forum discussion earlier today about some buttons not being compatible with some versions of Safari. If using Safari try a different browser.
Kevin
@kthorngren thanks man, the problem with the buttons was that I switched to jQuery slim. I switched back to regular afterwards (3.1.1)
Hi there, I have the same problem that malxx had in the asp mvc razor universe
but no solution.
The error is:
DataTables warning: table id=example - Requested unknown parameter 'metricId' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
I'm getting this back (just 1st column example for now)
[{"metricId":"76"},
{"metricId":"77"},
{"metricId":"78"}
]
instead of
{"data":
[{"metricId":"76"},
{"metricId":"77"},
{"metricId":"78"}
]
}
Is there a way of forcing the "data:" parameter to be included in the json data that I get back from the server? Am I doing something obviously wrong here.
Just tearing my hair out why I couldn't get malxx's solution to work.
-Andy
Probably would be good to look at the full response from the server. There is more than just the data the should be in the response when using server side processing. If you can't post a link to your page then start with the debugger.
Kevin
Firstly I would ask if you actually need server-side processing? Are you working with 50k records or more? If so, fine, keep it - but if less then remove it. Server-side processing will just add complexity.
The issue is that your JSON return from the server is not complete for server-side processing. You have to return an object rather than just a plain array for server-side processing, since it needs information other than just the data to display.
Allan
Hi Allan, I've figured out how to get the data back from the server, only problem now is for sorting and that's depending on getting an http: request back from the server
but nothing coming back, am I doing something obviously wrong here?
STOP PRESS sorted, will post details of solution for edification of others tomorrow.
Thanks, Andy
Hi There, firstly the function call I got to work was thus:
This is working off sql server tables.
also to do with tables how do you get the row data for the row retrived?
I tried this
It works with simple td based table data but not from a database, any ideas?
Thanks Andy
You are accessing it like an array, but you've configured DataTabels to expect objects (and indeed are loading it with objects). Use
data.metricId
.Allan