DataTables warning: requested unknown parameter '0' from data source for row '0'

Anyone please know what is wrong with the very simple HTML file below?

enter image description here

I'm just trying to use an array of objects as a data source for DataTables:

tests.html:

<html> <head> <link type="text/css" rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css"> <link type="text/css" rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.2/css/jquery.dataTables_themeroller.css"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script> <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.2/jquery.dataTables.min.js"></script> <script type="text/javascript"> var data = [ {"Name":"UpdateBootProfile","Result":"PASS","ExecutionTime":"00:00:00","Measurement":[]}, {"Name":"NRB Boot","Result":"PASS","ExecutionTime":"00:00:50.5000000","Measurement":[{"TestName":"TOTAL_TURN_ON_TIME","Result":"PASS","Value":"50.5","LowerLimit":"NaN","UpperLimit":"NaN","ComparisonType":"nctLOG","Units":"SECONDS"}]}, {"Name":"NvMgrCommit","Result":"PASS","ExecutionTime":"00:00:00","Measurement":[]}, {"Name":"SyncNvToEFS","Result":"PASS","ExecutionTime":"00:00:01.2500000","Measurement":[]} ]; $(function() { var testsTable = $('#tests').dataTable({ bJQueryUI: true, aaData: data, aoColumns: [ { mData: 'Name' }, { mData: 'Result' }, { mData: 'ExecutionTime' } ] }); }); </script> </head> <body> <table id="tests"> <thead> <tr> <th>Name</th> <th>Result</th> <th>ExecutionTime</th> </tr> </thead> <tbody> </tbody> </table> </body> </html> 

UPDATE: Well, I have a response from the author for using a newer version of DataTables or renaming mData to mDataProp

+59
jquery-datatables
May 14 '13 at 9:29
source share
12 answers

You are using an array of objects. Can you use a two-dimensional array instead?

http://www.datatables.net/examples/data_sources/js_array.html

See this jsfiddle: http://jsfiddle.net/QhYse/

I used such an array and it worked fine:

 var data = [ ["UpdateBootProfile","PASS","00:00:00",[]] , ["NRB Boot","PASS","00:00:50.5000000",[{"TestName":"TOTAL_TURN_ON_TIME","Result":"PASS","Value":"50.5","LowerLimit":"NaN","UpperLimit":"NaN","ComparisonType":"nctLOG","Units":"SECONDS"}]] , ["NvMgrCommit","PASS","00:00:00",[]] , ["SyncNvToEFS","PASS","00:00:01.2500000",[]] ]; 

Edit to include an array of objects

Possible solution to this question: jQuery DataTables fnrender with objects

This jsfiddle http://jsfiddle.net/j2C7j/ uses an array of objects. In order not to get an error, I had to fill it with three empty values ​​- I know that this is less than optimal. You can find the best way using fnRender, please write if you do.

 var data = [ ["","","", {"Name":"UpdateBootProfile","Result":"PASS","ExecutionTime":"00:00:00","Measurement":[]} ] ]; $(function() { var testsTable = $('#tests').dataTable({ bJQueryUI: true, aaData: data, aoColumns: [ { mData: 'Name', "fnRender": function( oObj ) { return oObj.aData[3].Name}}, { mData: 'Result' ,"fnRender": function( oObj ) { return oObj.aData[3].Result }}, { mData: 'ExecutionTime',"fnRender": function( oObj ) { return oObj.aData[3].ExecutionTime } } ] }); }); 
+24
May 14 '13 at 11:02
source share

The parameter is null or undefined . Just add this line to the attributes:, ,"columnDefs": [ { "defaultContent": "-", "targets": "_all" } ]

Example:

 oTable = $("#bigtable").dataTable({ "columnDefs": [{ "defaultContent": "-", "targets": "_all" }] }); 

The warning field will not be displayed again, any empty values ​​will be replaced with what you specified.

+58
Nov 10 '15 at 20:59
source share

It tormented me for more than an hour.

If you use the dataSrc parameter and the defs column, make sure they are in the right places. In ajax settings, I nested the column definitions and lost too much time to figure this out.

It's good:

good

This is not good:

enter image description here

A subtle difference, but real enough to cause hair loss.

+9
Jul 07 '17 at 21:18
source share

I had the same problem. It turns out that in my case, I missed the comma after the last column. 30 minutes of my life wasted, I'll never be back!

enter image description here

+5
Jul 31 '15 at 19:09
source share

Make sure the column names match. They are case sensitive. Here, in my case, I got this error when the column names of my model are encrypted, and I used all the lowercase letters in the ajax request data.

So, I decided by matching the column names in exactly the same way as the existing model names.

DataTable binding

 $("#Customers").DataTable({ ajax: { url: "/api/customers/", dataSrc: "" }, columns: [ { data: "Name", render: function (data, type, customer) { return "<a href='/customers/edit/" + customer.Id + "'>" + customer.Name + "</a>"; } }, { data: "Name" }, { data: "Id", render: function (data) { return "<button class='btn-link js-delete' data-customer-id=" + data + ">Delete</button>"; } } ] }); 

Web API Method:

  public IEnumerable<Customer> GetCustomers() { return _context.Customers.ToList(); } 

My model: -

  public class Customer { public int Id { get; set; } [Required] [StringLength(255)] public string Name { get; set; } [Display(Name="Date Of Birth")] public DateTime? BirthDate { get; set; } public bool isSubscribedToNewsLetter { get; set; } public MembershipType MembershipType { get; set; } [Display(Name="Membership Type")] [Required] public byte MembershipTypeId { get; set; } } 

so here, in my case, iam fills in the data using columns (Name, Name, Id) .. iam duplicates the second column name for verification.

+3
Mar 16 '17 at 19:31
source share

On the DataTables website:

Each cell in DataTables requests data and when DataTables tries to get data for a cell and cannot do this, it will cause a warning that the data is not available where it was expected to be. Warning message:

DataTables warning: table id = {id} - requested unknown parameter ' {parameter} ' for row {row-index}

Where:

{id} is replaced by the DOM identifier of the table that caused the error

{parameter} is the name of the data parameter. DataTables Requests

{row-index} is the index of the inner row of DataTables for rwo that caused the error.

So, to break it, DataTables requested the data for this row, {parameter} , and there is no data, or is it null or undefined .

See the technical note on the DataTables website for more information.

+2
May 7, '15 at 21:29
source share

I ran into this problem because I messed up the return keyword in custom rendering in the Columns section

 columns: [ {.... 'data': function(row, type, val, meta) { if (row.LetterStatus) return '@CultureHelper.GetCurrentCulture()' == 'ar'? row.LetterStatus.NameInArabic: row.LetterStatus.NameInEnglish; else row.LetterStatusID.toString();// here is the problem because I messed the Return key keyword }, ...... } 

The problem in my code is that I messed return keyword in else clause

so I changed it to

 .... else return row.LetterStatusID.toString();// messed return keyword added ..... 
+2
Sep 27 '16 at 8:05
source share

This is a very common case in DataTables when it cannot find a specific query field in the DataTable configuration.
For example:

  "aoColumns": [{ mData: 'mobile', sWidth: "149px;" }, { mData: 'name', sWidth: "121px;" }, { mData: 'productName', sWidth: "116px;" } }]; 

Here, if the DataTable does not get the above properties. This will generate this warning:

DataTables warning: requested unknown parameter '0' from data source for row '0'

To overcome this, you just need to set the default value to "aoColumns"

For example:

  "aoColumns": [{ mData: 'mobile',sDefaultContent : '',sWidth: "149px;" }, { mData: 'name',sDefaultContent : '', sWidth: "121px;" }, { mData: 'productName',sDefaultContent : '', sWidth: "116px;" } }]; 

sDefaultContent suppresses the warning.
Note. This property may be changed depending on the version of dataTables you are using.

+2
Jan 09 '18 at 10:03
source share

If you use knockout.bindings.dataTables.js you can edit the file and replace this line

 dataTable.fnAddData(unwrappedItems); 

from

 if (unwrappedItems.length > 0) { dataTable.fnAddData(unwrappedItems); } 

It helped me and I hope that helps you.

+1
Sep 25 '15 at 12:56
source share

In my weird scenario, I had another column that did not always return a value in the render function. return null solved my problem.

+1
Dec 06 '17 at 16:10
source share

If someone uses the new DataTables (which is surprising), and you want to use an array of objects, you can easily do this using the column option. See the following link for an excellent example on this.

DataTables with an array of objects

I have been struggling with this for the past 2 days, and this solved it. I did not want to switch to multidimensional arrays for other code reasons, so I was looking for such a solution.

0
Jan 26 '18 at 2:31
source share

In my case, I had a capital letter "C" for the column options in the data settings. Spent 2 hours to figure it out !!!!

 "ajax": { "url": "URL", "type": "GET", "contentType": "application/json", "data": function (d) { return { id: Id }; }, "dataSrc": "" }, "columns": [ { data: 'field1' }, { data: 'field2' } ], "columnDefs": [{ "targets": [-1, -2], "orderable": false }, { "defaultContent": "-", "targets": "_all" }], "order": [[0, "asc"]] 
0
Jan 31 '19 at 18:57
source share



All Articles