The dreaded "Requested unknown parameter for row 0, column 0"

The dreaded "Requested unknown parameter for row 0, column 0"

martinconnollybartmartinconnollybart Posts: 18Questions: 7Answers: 0

Another hair-tearing-out problem! I cannot figure out why I am getting this error, no matter how I configure the columns. I have tried different sets of columns but the first one is always throwing up this error.
Here is my dead simple PHP:

    Editor::inst( $db, 'TApplications' )
        ->fields(

            Field::inst( 'TApplications.purpose' ),
            Field::inst( 'TApplications.reqtotal')
        ) 
        ->where ('TApplications.successful','No','!=')      
        ->debug(true)
        ->process( $_POST )
        ->json();

Javascript:

var spreadsheetTable = new DataTable('#Sheet', {

 ajax: 'php/table.TApplicationsSpreadsheet.php',

 columns: [
               {
                   "data": "purpose"
               },
               {
                  "data": "reqtotal", "label":"Total Requested"
                }
            ],
            dom: 'Bfrtip',
            scrollY: "500px",
            "paging": false,
            "autoWidth": false 
        } );

HTML:

<h1>Applications Spreadsheet</h1>

<div class="container" style="width:90%; padding-left: 70px">
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="Sheet" >
<thead>
<tr>
<th>Purpose</th>
<th>Total Requested</th>
</tr>
</thead>
</table></div>

And the data being returned looks like this:

data
:
[{DT_RowId: "row_5",…}, {DT_RowId: "row_11",…}, {DT_RowId: "row_12",…},…]
[0 … 99]
0
:
{DT_RowId: "row_5",…}
DT_RowId
:
"row_5"
TApplications
:
{purpose: "Project Worker salary + associated core costs", reqtotal: "35555.0000"}
1
:
{DT_RowId: "row_11",…}
DT_RowId
:
"row_11"
TApplications
:
{purpose: "Replace Lottery Funding for Training Co-ord", reqtotal: "26584.0000"}

But I get this error message:

DataTables warning: table id=Sheet - Requested unknown parameter 'purpose' for row 0, column 0. For more information about this error, please see https://datatables.net/tn/4

Note that this happens no matter which combination of columns I try (so far at least).

So what is going wrong? Apologies if this is really obvious.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,439Questions: 1Answers: 10,459 Site admin
    Answer ✓

    You don't have a field in the JSON called purpose. That parameter is nested in the TApplications object.

    If you change your columns to be:

                   {
                       "data": "TApplications.purpose"
                   },
                   {
                      "data": "TApplications.reqtotal", "label":"Total Requested"
                    }
    

    I would expect it to work.

    If you aren't planning to add a join to the table, you could simply by removing the TApplications. from both the fields in the PHP and the data property in the column options for the DataTable.

    Allan

  • martinconnollybartmartinconnollybart Posts: 18Questions: 7Answers: 0

    Thanks Allan, that sorted it. I think I've forgotten the qualifying object name before....

Sign In or Register to comment.