An mDataProp, a javascript array, and a Canadian walk into a bar.

An mDataProp, a javascript array, and a Canadian walk into a bar.

bluebaronbluebaron Posts: 33Questions: 0Answers: 0
edited February 2012 in DataTables 1.9
The Canadian ducks. Boom!

Having a problem with this error: DataTables warning (table id = 'services_table'): Requested unknown parameter '1' from the data source for row 0.

Looking around the site I've come to understand that this is usually an issue with the definitions for aoColumns and the json not matching up nicely.

This worked when I just set aaData to data[current_view] on table creation.

Here's my code:

[code]
$('#' + views[view].DataName + '_table').dataTable({
"aoColumns": properties,
"sScrollY": "600px",
"sScrollX": "100%",
"sPaginationType": "full_numbers",
"bJQueryUI": true
});

$.getJSON('/results_update?view=' + current_view + '&host_id=' + $('#select_hosts').val(), function (data) {
var table = $('#' + current_view + '_table').dataTable();
table.fnClearTable();
table.fnAddData(data[current_view]);

});

[/code]

Here's what's in properties:
[code]
[Object { mDataProp="name", sWidth="150px"}, Object { mDataProp="password_age", sWidth="150px"}, Object { mDataProp="privilege", sWidth="150px"}, 21 more...]
[/code]

Here's my table:
[code]
NamePassword AgePrivilegeHome DirCommentDisabledNo Password RequiredPassword Can't ChangeLockedDon't Expire PasswordPassword ExpiredTypePrint OperatorCommunications OperatorServer OperatorAccount OperatorFull NameWorkstationsLast LoginLast LogffAccount ExpiresBad Password LoginsLogin CountLogon Server
[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Heh - and the points for the best forum post title go to - a Canadian...

    You are correct this this warning normally is caused by a mismatch in the columns defined that those in the table. I would suggest adding console.log( properties.length ) to the script to check that is of known length and also console.log( $('#' + views[view].DataName + '_table thead td').length ); . I would guess they won't match.

    Allan
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    edited February 2012
    The thing is that the length of that is 27 because there are 27 rows. Inside

    [code]
    {
    "services": [
    {
    "display_name": "Application Layer Gateway Service",
    "service_name": "ALG",
    "process_id": 1112,
    "status": "SERVICE_RUNNING",
    "startup_type": "SERVICE_DEMAND_START",
    "binary_path": "C:\\WINDOWS\\System32\\alg.exe",
    "username": "NT AUTHORITY\\LocalService",
    "description": "Provides support for 3rd party protocol plug-ins for Internet Connection Sharing and the Windows Firewall."
    }, ... //26 more
    ]
    }
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    So both properties and the number of columns int he HTML is 27?

    Allan
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    No. The properties are 8. The rows are 27. The HTML was unexpected value(16). Looking into why that is.
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    Ah. Because it's counting the /td. So it looks okay.
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    27 rows. 8 columns. Still having issues.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Okay the thing to do is fire up Firebug or Inspector and type:

    console.dir( $.fn.dataTableSettings[0].aoColumns );

    then have a look through that to check what mDataProp is for each of the columns.

    In your original post when you mention what "properties" looks like it says "21 more..." at the end. Given you have only 8 columns, that seems a bit odd.

    Allan
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    My bad on that one. You're right that was for another table. I got the tables mixed up on here but not in the code.
    I'll look into that but I found out that the issue is actually with this line:

    [code]
    var table = $('#' + current_view + '_table').dataTable();
    [/code]

    It must not like something about my initial configuration.
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    It doesn't like the fact that I didn't set aaData.
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    Yes. That's it. How ... can I get around that?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I don't really understand I'm afraid - aaData is not a required parameter (for example: http://datatables.net/release-datatables/examples/basic_init/zero_config.html ).

    Are you able to link me to a test page?

    Allan
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    I bet it's required if you set the aoColumns with mDataProp. I don't have an externally viewable page.
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    edited February 2012
    Okay. Here's the thing:

    Works:
    [code]
    $('#services_table').dataTable({
    //"aoColumns": properties,
    "sScrollY": "600px",
    "sScrollX": "100%",
    "sPaginationType": "full_numbers",
    "bJQueryUI": true,
    });
    var table = $('#services_table').dataTable();
    [/code]

    Does not work:
    [code]
    $('#select_hosts').click(function () {
    UpdateResults();
    });

    function UpdateResults() {

    $.getJSON('/results_update?view=' + current_view + '&host_id=' + $('#select_hosts').val(), function (data) {
    var table = $('#services_table').dataTable(); //error here
    table.fnClearTable();
    table.fnAddData(data[current_view]);

    });

    [/code]
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    Same line of code, different location in the program.
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    Sigh. I don't know what to do. I wish I had port 80 out so you could look at this. I think it must have something to do with scope.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > var table = $('#services_table').dataTable(); //error here

    That line gives you the error about parameter 1 for row zero not existing!? Has the table already been initialised by that time and you are just getting the reference to it at that point?

    Which version of DataTables are you using here?

    Allan
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    DataTables warning (table id = 'services_table'): Requested unknown parameter '1' from the data source for row 0
    /**
    * @summary DataTables
    * @description Paginate, search and sort HTML tables
    * @version 1.9.0
    * @file jquery.dataTables.js
    * @author Allan Jardine (www.sprymedia.co.uk)
    * @contact www.sprymedia.co.uk/contact
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    The top example that works is in the document ready. The rest is in another function.
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    idk wtf is going on here
    Tried this on the jsbin:

    $(document).ready(function() {
    $('#example').dataTable();
    var table = $('#example').dataTable();
    UpdateResults();

    $('body').append('blah');
    $("#blah").click(function(){UpdateResults();return false;});

    } );



    function UpdateResults() {

    var table = $('#example').dataTable();
    alert(table);

    }
    and it worked just fine
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    Okay. Figured out the why. Maybe you can help me with the how.
    I have a display area. When the user selects what table he or she would like to see, I dump the inner html of a div that contains just the table in it, to the display area like so:

    [code]
    var table = $('#services_table').dataTable(); // no error
    $('#results_container').html($('#' + current_view + '_results').html());
    var table = $('#services_table').dataTable(); //error
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Ah okay - you are replacing the DOM nodes doing that - i.e. #services_table before !== #services_table after (I presume the services table is inside the #results_container?). So basically you've whipped the table out from under DataTables' "feet". If you want to destroy a table you should explicitly do so using fnDestroy - then you can reinitialise it any time.

    Allan
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    Sorry, I had to leave on a Dr's appt. yesterday. Not only was I whipping the table out but I was poisoning the DOM as well.
This discussion has been closed.