DataTables warning - Requested unknown parameter

DataTables warning - Requested unknown parameter

larrybglarrybg Posts: 14Questions: 5Answers: 0

I'm populating survey results in the datatable. The results saved in the JSON format.
The problem is not every question in the survey is required, or there is a hidden question that will be visible if user answers "YES" on the first question. So users may not see a question or skip it. As a result, JSON doesn't have all answers and may contain less data than the number of questions/columns. When I load my table I receive a warning message "DataTables warning: table id=dataTable - Requested unknown parameter 'framework' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4".

Here is the init code:

$('#dataTable').DataTable({
        "data": json.data,
         "columns": json.columns,
         "defaultContent": ""
});

I wanted to suppress these messages with "defaultContent" but it doesn't work.

Here is the sample data:

{
    "columns":
    [
        {"data":"frameworkUsing","title":"Do you use any front-end framework like Bootstrap?"},
        {"data":"framework","title":"What front-end framework do you use?"},
        {"data":"mvvmUsing","title":"Do you use any MVVM framework?"},
        {"data":"mvvm","title":"What MVVM framework do you use?"},
        {"data":"about","title":"Please tell us about your main requirements for Survey library"}
    ],

    "data":
    [
        {"frameworkUsing":"No","mvvmUsing":"No","about":"wwsw"},
        {"frameworkUsing":"No","mvvmUsing":"No","about":"wddw"},
        {"frameworkUsing":"No","mvvmUsing":"No","about":"cvvbbvbv"},
        {"frameworkUsing":"Yes","framework":["Bootstrap"],"mvvmUsing":"Yes","mvvm":["AngularJS"],"about":"text"}
    ]
}

Can you please help?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955
    Answer ✓

    I think the problem is you need to use the columns.defaultContent option within your json.columns variable.

             "columns": json.columns,
             "defaultContent": ""  <<remove this and move to your json.columns variable
    

    Kevin

  • larrybglarrybg Posts: 14Questions: 5Answers: 0

    Hi Kevin,
    Yes, you are right, I was inserting into the wrong place.
    Here is the working code:

    "columns":
        [
            {"data":"frameworkUsing", "defaultContent":"", "title":"Do you use any front-end framework like Bootstrap?"},
            {"data":"framework", "defaultContent":"", "title":"What front-end framework do you use?"},
            {"data":"mvvmUsing", "defaultContent":"", "title":"Do you use any MVVM framework?"},
            {"data":"mvvm", "defaultContent":"", "title":"What MVVM framework do you use?"},
            {"data":"about", "defaultContent":"", "title":"Please tell us about your main requirements for Survey library"},
            
        ],
    

    Thank you!

This discussion has been closed.