fnGetData returns undefined for rows using mdata
fnGetData returns undefined for rows using mdata
Hi,
In my DataTables I am trying to pass a unique ID with fnGetData that is a hidden column when my Editor form is submitted. The ID is not being passed (it is coming up as undefined if I console.log the event) apparently due to the fact that the hidden ID column is listed in my aoColumnDefs with 'mData'. If I remove that column from 'mData' then it returns the ID as expected. However, I also get this error:
DataTables warning (table id = 'gatewayTable'): Requested unknown parameter '5' from the data source for row 3
and the submit fails.
Any idea why these two things are clashing? Here is the related code.
[code]
oTable = $('##gatewayTable').dataTable({
"sDom": "<'row-fluid'<'span5'T><'span3'l><'span4'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page",
"sInfoFiltered": "(_MAX_ total)"
},
"aoColumnDefs": [
{ "aDataSort": [ 2, 1, 0 ], "aTargets": [ 2 ] },
{ "mData": "mac", "aTargets": [ 0 ] },
{ "mData": "name", "aTargets": [ 1 ] },
{ "mData": "location_id", "aTargets": [ 2 ] },
{ "mData": "type", "aTargets": [ 3 ] },
{ "mData": "status_cde", "aTargets": [ 4 ] },
{ "mData": "gateway_id", "aTargets": [ 5 ] }
],
"oTableTools": {
"sRowSelect": "single",
"sSelectedClass": "row_selected",
"fnRowSelected": function ( node ) {
gateway_id = oTable.fnGetData(node[0])[5];
console.log(oTable.fnGetData(node[0])[5]);
},
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
});
[/code]
Thanks,
Carl
In my DataTables I am trying to pass a unique ID with fnGetData that is a hidden column when my Editor form is submitted. The ID is not being passed (it is coming up as undefined if I console.log the event) apparently due to the fact that the hidden ID column is listed in my aoColumnDefs with 'mData'. If I remove that column from 'mData' then it returns the ID as expected. However, I also get this error:
DataTables warning (table id = 'gatewayTable'): Requested unknown parameter '5' from the data source for row 3
and the submit fails.
Any idea why these two things are clashing? Here is the related code.
[code]
oTable = $('##gatewayTable').dataTable({
"sDom": "<'row-fluid'<'span5'T><'span3'l><'span4'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page",
"sInfoFiltered": "(_MAX_ total)"
},
"aoColumnDefs": [
{ "aDataSort": [ 2, 1, 0 ], "aTargets": [ 2 ] },
{ "mData": "mac", "aTargets": [ 0 ] },
{ "mData": "name", "aTargets": [ 1 ] },
{ "mData": "location_id", "aTargets": [ 2 ] },
{ "mData": "type", "aTargets": [ 3 ] },
{ "mData": "status_cde", "aTargets": [ 4 ] },
{ "mData": "gateway_id", "aTargets": [ 5 ] }
],
"oTableTools": {
"sRowSelect": "single",
"sSelectedClass": "row_selected",
"fnRowSelected": function ( node ) {
gateway_id = oTable.fnGetData(node[0])[5];
console.log(oTable.fnGetData(node[0])[5]);
},
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
});
[/code]
Thanks,
Carl
This discussion has been closed.
Replies
fnGetData returns the original data source object (or more specifically in 1.9- an exact copy of it). It appears that you are using object notation (from your use of mData ), but then you use array notation in the row selected function. I rather suspect you want something like `fnGetData(node[0]).location_id` rather than trying to access an object as an array.
Regards,
Allan