An mDataProp, a javascript array, and a Canadian walk into a bar.
An mDataProp, a javascript array, and a Canadian walk into a bar.
bluebaron
Posts: 33Questions: 0Answers: 0
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]
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]
This discussion has been closed.
Replies
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
[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]
Allan
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
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.
Are you able to link me to a test page?
Allan
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]
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
/**
* @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
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
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]
Allan