"Requested unknown parameter" when using mDataProp (incl. debug data)

"Requested unknown parameter" when using mDataProp (incl. debug data)

MikeZuberMikeZuber Posts: 3Questions: 0Answers: 0
edited April 2012 in DataTables 1.9
Allan,

Hey there. I was hoping you could help me with an issue I'm seeing with DataTables v1.9.0 + .NET 3.5 ScriptServices. I keep getting the following error when my table is first being rendered:

[quote]DataTables warning (table id = 'tblRequests'): Requested unknown parameter 'Id' from the data source for row 0[/quote]

I used your debugger bookmarklet and the code for the debug data is: uwenar

The thing that really bothers me is that once you click "OK" to clear the error, the table renders fine. (There are cosmetic issues, but they are unrelated.) I'm interpreting this to mean the JSON data being returned by my server is formatted correctly (albeit as an array of Objects, not a 2D array).

My issue is similar to this post:

http://datatables.net/forums/discussion/9030/using-fnrender-with-ajax-source-datatable/p1

I can make the error go away by specifying a value for "sDefaultContent" for each node in my aoColumnDefs array. Unlike that previous post, though, I have to specify sDefaultContent for *every* node, or else I'll still get the error. (The only change being that the error will reference the first node that does not have a sDefaultContent specified.) This workaround seems rather clunky and I was hoping you could recommend a better one.

Here is the JSON response my server generates:

{"d":{"sEcho":"1","iTotalRecords":2,"iTotalDisplayRecords":2,"aaData":[{"__type":"ELB.CIA.Model.ImpactReport","Id":124,"Description":"test","SubmittedOn":"\/Date(1332520862000)\/","SubmittedBy":"PERSON1","CompletedOn":null,"SourceSystem":0,"SourceId":0,"Status":0,"ViewOnlyInd":false},{"__type":"ELB.CIA.Model.ImpactReport","Id":120,"Description":"fake1","SubmittedOn":"\/Date(1332434462000)\/","SubmittedBy":"PERSON2","CompletedOn":null,"SourceSystem":0,"SourceId":0,"Status":2,"ViewOnlyInd":false}]}}

FYI: the "d" wrapper generated by .NET is dealt with by a converter plugged into $.ajaxSetup(),

Thanks for your time.

-Mike

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Mike,

    Thanks for the debug trace! Generally your initialisation looks fine, but why are you passing in an array of nulls for aaData? It looks like you don't need to pass anything in at all for aaData - I'd just remove that and use the Ajax source as your data source.

    Allan
  • MikeZuberMikeZuber Posts: 3Questions: 0Answers: 0
    Allan,

    Thanks for responding. Given that there's a workaround (simply provide an empty string for sDefaultContent for every element in aoColumnDefs ), this clearly isn't a critical issue. It's a bizarre one, though. Were you able to replicate this issue? Or am I going crazy?

    As for aaData, I copied the code above from another project as a starting point and didn't think to get rid of it. Thanks for pointing out that I can remove it.

    -Mike
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Does just removing aaData not fix the problem for you? The warning is saying that DataTables is looking for data in a row and the data doesn't exist - I assumed that it was the nulls at fault.

    Allan
  • vinod_ccvvinod_ccv Posts: 75Questions: 0Answers: 0
    edited September 2012
    Allan,
    Me also experiencing same issue the similar issue. In my MYSQL database table named browsers id is the primary field. But when the script runs it shows warning ."DataTables warning (table id = 'tblRequests'): Requested unknown parameter 'Id' from the data source for row 0" On closing the same table gives data except id.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Can you either run your table through the debugger or give us a link to the page please? If DataTables is giving you that warning then it's because the parameter 'id' isn't present in the data being returned from the server.

    Allan
  • vinod_ccvvinod_ccv Posts: 75Questions: 0Answers: 0
    Nothing I changed in 'Editor-1.2.1/examples/inlineControls.html' I tried to add an additional column which gives that id field(primary) from mysql data base. It doesn't work. But it works if i changed `version`. I m using my sql version5.0 and all the other example codes as it is. You may please try it from your end please. why { "mDataProp": "id" }, does nt work?
  • vinod_ccvvinod_ccv Posts: 75Questions: 0Answers: 0
    This is my code ...


    [code] // DataTables init
    $('#example').dataTable( {
    "sDom": "Tfrtip",
    "sAjaxSource": "php/browsers.php",
    "aoColumns": [
    { "mDataProp": "id" }, /////see the only change i made//
    { "mDataProp": "browser" },
    { "mDataProp": "engine" },
    { "mDataProp": "platform" },
    { "mDataProp": "grade", "sClass": "center" },
    {
    "mDataProp": null,
    "sClass": "center",
    "sDefaultContent": 'Edit / Delete'
    },
    {
    "mDataProp": null,
    "sClass": "center",
    "sDefaultContent": 'Brows'
    }
    ]
    } );[/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > { "mDataProp": "id" }, /////see the only change i made//

    Fair enough. Did you also change the server-side script to return an 'id' property in the JSON source? There isn't one there by default, so if you didn't add one in (which is sounds like you haven't since this was the only change you made), then DataTables is quite rightly saying that there is no 'id' property.

    Allan
  • vinod_ccvvinod_ccv Posts: 75Questions: 0Answers: 0
    Oops I didn't notice that. I thought it might be there by default. Added Field::inst( 'id' ), in browsers .php. It works fine. Thank you so much for your quick and exact help.
This discussion has been closed.