Trying to access rowdata in render function with ajax datasource, getting undefined
Trying to access rowdata in render function with ajax datasource, getting undefined
bickle
Posts: 8Questions: 0Answers: 0
I'm getting an undefined value when I try to reference the row parameter in the render function. When I try the example at http://next.datatables.net/examples/advanced_init/column_render.html, that works fine. But when I switch to an ajax datasource, the row parameter is undefined. I have an example here: http://live.datatables.net/lijoyay/2/edit For the purposes of the example, I'm just joining the first 2 columns.
Here's the debug data code for what I'm actually working on, in case it is of any relevance: ivoqan
Here's the debug data code for what I'm actually working on, in case it is of any relevance: ivoqan
This discussion has been closed.
Replies
The problem with the code is `row[1]` - that assumes the data is an array. But it isn't - you've given it an object, so there are no array indexes... You want to use something like `row.position` .
Allan
[quote]You won't like it, but it looks like it is working as expected[/quote]
Heh, I fully expected that to be the case. I'm on a javascript/ajax crash course so this is all new to me.
Thanks again!
If anyone wants a working example, this is what works with the example posted above:
[code]$(document).ready(function() {
$('#example').dataTable( {
"ajax": "/ajax/objects.txt",
"columns": [
{ "title": "Name & Position",
"data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
],
"columnDefs": [
{
"render": function ( data, type, row ) {
return data +', '+ row.position;
},
"targets": 0
}
]
} );
} );[/code]