Trying to access rowdata in render function with ajax datasource, getting undefined

Trying to access rowdata in render function with ajax datasource, getting undefined

bicklebickle Posts: 8Questions: 0Answers: 0
edited April 2014 in DataTables 1.10
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

Replies

  • allanallan Posts: 61,627Questions: 1Answers: 10,090 Site admin
    Thanks for the test case. You won't like it, but it looks like it is working as expected :-).

    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
  • bicklebickle Posts: 8Questions: 0Answers: 0
    edited April 2014
    Wow, I could've sworn I tried that. And yet I try it this morning and it worked like a charm.

    [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]
This discussion has been closed.