[SOLVED] Requested unknown parameter '0' from the data source for row 0

[SOLVED] Requested unknown parameter '0' from the data source for row 0

cdevidalcdevidal Posts: 6Questions: 0Answers: 0
edited May 2012 in General
I'm getting "Requested unknown parameter '0' from the data source for row 0" and it's driving me batty. I've read all of the forum entries and either I just missed it or it wasn't posted.

The debug report (which is *incredible* by the way):
http://debug.datatables.net/iyaruy

Browser is Firefox 12.0 on WinXP SP3.

It appears that DataTables is inserting extra columns. (Is it?) See the 0, 1, 2 columns?
{
"Backup status": "Success",
"Monitoring status": "Success",
"Hostname": "usvxapunixp01",
"0": null,
"1": null,
"2": null
}

I say that because this is what the JSON looks like:
{"iTotalRecords": 1, "aaData": [{"Backup status": "Success", "Monitoring status": "Success", "Hostname": "examplehost"}], "sEcho": 0, "iTotalDisplayRecords": 10}

And the HTML:



Hostname
Monitoring status
Backup status



Please assist. Thanks!! Great product.

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Glad you like the debugger :-).

    So the issue here is that you need to tell DataTables what parameter from your JSON you want to assign to each column. At the moment you have "Monitoring status" etc, but DataTables can have no idea that you want that attached to a given column (yes the names match, but that's very unusual :-) ).

    The way to do it is to use mDataProp - fully described in this blog post: http://datatables.net/blog/Extended_data_source_options_with_DataTables

    Allan
  • cdevidalcdevidal Posts: 6Questions: 0Answers: 0
    OK I read that blog article and didn't think it applied but I'll check again. Is there any reason that following the examples on the website failed? I didn't believe mine deviated from the example all that much.
  • cdevidalcdevidal Posts: 6Questions: 0Answers: 0
    Worked. How do you do it??
  • cdevidalcdevidal Posts: 6Questions: 0Answers: 0
    If the debug data doesn't contain private data, and it looks like it doesn't, I'd like to leave it up for other's sake. Can you comment?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    The debug includes the data from the table - but nothing else (doesn't include your IP, browser etc) :-).

    Good to hear you got it working.

    Allan
  • jaguayojaguayo Posts: 5Questions: 0Answers: 0
    I've got the same problem, including the additional column (which I believe is the cause of the error and lack of returned rows - http://debug.datatables.net/ikusew

    I followed the post and links to the use of mDataProp. I've tried reducing input params, using more, alternative values - the works. I'd appreciate a few minutes of your time to look over my usage and tell me where I've gone wrong.
    Thanks in advance-


    USAGE --
    $(document).ready(function() {
    $('#tbl_vendors').hide();
    var oTable = $('#tbl_vendors').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "iDisplayStart": 0,
    "iColumns": 1,
    "sAjaxDataProp": "aaData",
    "sAjaxSource": "fws_json_dt.pl?rc=get_vendors_dt",
    "aoColumns " : [ { "mDataProp": "vname" } ],
    "oLanguage": {
    "sSearch": "Vendor Name: ",
    "sZeroRecords": "No records matched your criteria"
    }
    } );

    /* Draw table when contents of search textbox changes */
    $('div.dataTables_filter input').keyup( function () {
    var oSettings = oTable.fnSettings();

    if ($('.dataTables_filter input').val().length == 0) {
    oSettings._iDisplayLength = 1;
    $('#tbl_vendors_paginate')[0].style.display = "none";
    }
    else {
    oSettings._iDisplayLength = 10;
    $('#tbl_vendors_paginate')[0].style.display = "block";
    }
    oTable.fnDraw();
    } );

    // These objects are hidden by default, allowing query to bring back results before displaying table
    $('#div_vendors').show();
    $('#tbl_vendors').show();

    // Set focus on filter textbox
    $('.dataTables_filter input:text').focus();
    }

    JSON source --

    { "sEcho": 4, "iTotalRecords": 57, "iTotalDisplayRecords": 57, "aaData" : [ {
    "vname":"SMITH, JOHN"
    }
    ] }
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Thanks for the debug trace. For some reason the mDataProp for your initialisation doesn't look like it is being picked up. Can you link me to a test case showing the issue?

    It would also be worth upgrading to the latest release of DataTables.

    Allan
  • jaguayojaguayo Posts: 5Questions: 0Answers: 0
    Thanks, Allan. Unfortunately this is work being done for an intranet, so the URL is blocked. If you agree that mDataProp usage is correct and nothing else looks out of place, I'll upgrade first and see what results that brings.
  • jaguayojaguayo Posts: 5Questions: 0Answers: 0
    I upgraded to v1.9.4 - same result. I understand it may be difficult to address given that the interface is blocked, but I'm in the process of redeveloping legacy features on the intranet using DataTables. I'll keep playing with it some more - any additional suggestions you have are welcome. Thank you.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Can you run your table through the debugger again now that you've updated to 1.9.4 please?

    Allan
  • jaguayojaguayo Posts: 5Questions: 0Answers: 0
    http://debug.datatables.net/equsom

    I modified the JSON set to include two rows (wanted to see an odd/even row). The error went away, as did the row data - "0": null. However, table row values for both display the text "undefined", rather than the JSON value.
  • jaguayojaguayo Posts: 5Questions: 0Answers: 0
    Not to be redundant, but does this reflect what the HTML side should look like? --




    Vendor Name








     



    BTW - we have other forms running datatables, though this is the first to use server-side processing. Users are ecstatic about the product.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    You are getting undefined because you fnRender method is returning an undefined property of the data source object (there is no index `0` - just a property `vname` ).

    fnRender is depreciated in 1.9.4 and I'd strongly recommend you use mRender (and mData rather than mDataProp).

    Also, yes your HTML looks fine.

    > Users are ecstatic about the product.

    Excellent :-)

    Allan
This discussion has been closed.