DataTables error: Requested unknown parameter '1' from the data source for row 0

时光怂恿深爱的人放手 提交于 2020-01-06 02:46:07

问题


I'm trying to create a table using jQuery / DataTables using JSON data as a source. I have validated the data it is fine. Unfortunately I'm keep getting this error: "DataTables warning (table id='example'): Requested unknown parameter '1' from the data source for row 0". I'm not sure what am I doing wrong here:

JSON

dataSet = [
{
    "Month": "October",
    "Notices Received": "0",
    "Declined Participation": "0",
    "Selected Field Reviews": "0",
    "Selected File Review": "0",
    "Pending": "0",
    "Pending Previous Year": "0",
    "Controversial": "0",
    "GFP Reviews": "0",
    "NAD Appeals": "0",
    "Mediation Cases": "0",
    "Monthly Cost Savings": "$0.00",
    "Monthly Expenditure": "$0.00"
},
{
    "Month": "November",
    "Notices Received": "0",
    "Declined Participation": "0",
    "Selected Field Reviews": "0",
    "Selected File Review": "0",
    "Pending": "0",
    "Pending Previous Year": "0",
    "Controversial": "0",
    "GFP Reviews": "0",
    "NAD Appeals": "0",
    "Mediation Cases": "0",
    "Monthly Cost Savings": "$0.00",
    "Monthly Expenditure": "$0.00"
},
{
    "Month": "December",
    "Notices Received": "0",
    "Declined Participation": "0",
    "Selected Field Reviews": "0",
    "Selected File Review": "0",
    "Pending": "0",
    "Pending Previous Year": "0",
    "Controversial": "0",
    "GFP Reviews": "0",
    "NAD Appeals": "0",
    "Mediation Cases": "0",
    "Monthly Cost Savings": "$0.00",
    "Monthly Expenditure": "$0.00"
}];

JS:

$('#theJson').text(dataSet); //just for testing

$('#example').dataTable( {
  "aaData": dataSet,
  "aoColumns": [

        { "sTitle": "Month" },
        { "sTitle": "Notices Received" },
        { "sTitle": "Declined Participation" },
        { "sTitle": "Selected Field Reviews"},
        { "sTitle": "Selected File Reviews"},
        { "sTitle": "Pending"},
        { "sTitle": "Pending Previous Year"},
        { "sTitle": "Controversial"},
        { "sTitle": "GFP Reviews"},
        { "sTitle": "NAD Appeals"},
        { "sTitle": "Mediation Cases"},
        { "sTitle": "Monthly Cost Savings"},
        { "sTitle": "Monthly Expenditure"}
    ]

} );

HTML:

<table width="100%" id="example" border="0" cellspacing="0" cellpadding="0"></table>

All I get is the error message and the table header. The footer actually shows: "Showing 1 to 10 of 4,008 entries", which may indicate that it is looking at the data. Thanks!


回答1:


issue is "aaData": dataSet, accecpt array data,but you are not convert json data still,

check this,

var dataSet = [  {//Table Data }, { //Table Data } , { //Table Data } ];//Wrong Type (Still Json Format)

but excepted data format

var dataSet = [  [//Table Data ], [ //Table Data ] , [ //Table Data ] ];//Right Type (Now  Array Format)

Do convert json data to array data

var dataSet=[];
    $.each(o,function(i,k){
          dataSet.push( $.map(o[i], function(el) { return el; }));
    });
console.log(dataSet);

Here His demo...Click Here Demo

Now try it,



来源:https://stackoverflow.com/questions/24891849/datatables-error-requested-unknown-parameter-1-from-the-data-source-for-row-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!